@vite-hub/schedule 0.0.4 → 0.3.1

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 (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -0,0 +1,318 @@
1
+ import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
2
+ import { t as internalErrorDiagnostics } from "./error-diagnostics-DSkCJC_L.js";
3
+ import { toJsonSchema } from "@valibot/to-json-schema";
4
+ import * as v from "valibot";
5
+ //#region ../internal/src/standard-schema.ts
6
+ function readOwn(value, key) {
7
+ if (value === null || Object(value) !== value) return;
8
+ try {
9
+ return Reflect.get(Object(value), key);
10
+ } catch {
11
+ return;
12
+ }
13
+ }
14
+ /**
15
+ * Read a Standard JSON Schema projection without throwing.
16
+ *
17
+ * Returns `undefined` when the schema has no `~standard.jsonSchema`, when the library cannot represent the type
18
+ * (Zod throws for `Date`), or when the projection is not an object. Callers decide how to fall back.
19
+ */
20
+ function standardJsonSchema(schema, direction, target = "draft-2020-12", libraryOptions) {
21
+ const jsonSchema = readOwn(readOwn(schema, "~standard"), "jsonSchema");
22
+ const project = readOwn(jsonSchema, direction);
23
+ if (typeof project !== "function") return;
24
+ try {
25
+ const result = project.call(jsonSchema, libraryOptions ? {
26
+ target,
27
+ libraryOptions
28
+ } : { target });
29
+ return isRecordOrFunction(result) ? result : void 0;
30
+ } catch {
31
+ return;
32
+ }
33
+ }
34
+ //#endregion
35
+ //#region ../internal/src/valibot.ts
36
+ const valibotTargets = /* @__PURE__ */ new Set([
37
+ "draft-07",
38
+ "draft-2020-12",
39
+ "openapi-3.0"
40
+ ]);
41
+ function isValibotTarget(value) {
42
+ return valibotTargets.has(String(value));
43
+ }
44
+ /**
45
+ * Add Standard JSON Schema conversion to a plain Valibot schema. Valibot schemas validate as Standard Schema but carry
46
+ * no JSON Schema, so forms, tools, and model providers would get no shape for them. Other schemas, Valibot schemas that
47
+ * already convert, and async Valibot schemas return unchanged. The copy keeps every Valibot property, so validation
48
+ * does not change.
49
+ *
50
+ * `target` fixes the JSON Schema dialect. Without it, each conversion uses the dialect that the caller asks for.
51
+ */
52
+ function withValibotJsonSchema(schema, options = {}) {
53
+ const standard = schema["~standard"];
54
+ if (standard.vendor !== "valibot" || Reflect.get(schema, "async") === true) return schema;
55
+ if (Object.hasOwn(standard, "jsonSchema") && standard.jsonSchema) return schema;
56
+ const convert = (typeMode) => (request) => {
57
+ const target = options.target ?? request.target;
58
+ if (!isValibotTarget(target)) throw internalErrorDiagnostics.INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED({ target: String(target) });
59
+ return toJsonSchema(schema, {
60
+ target,
61
+ typeMode,
62
+ errorMode: "ignore"
63
+ });
64
+ };
65
+ return {
66
+ ...schema,
67
+ "~standard": {
68
+ ...standard,
69
+ jsonSchema: {
70
+ input: convert("input"),
71
+ output: convert("output")
72
+ }
73
+ }
74
+ };
75
+ }
76
+ //#endregion
77
+ //#region ../internal/src/operation-definition.ts
78
+ const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
79
+ const kinds = /* @__PURE__ */ new Set([
80
+ "read",
81
+ "write",
82
+ "destructive"
83
+ ]);
84
+ function invalidDefinition(name, reason) {
85
+ return internalErrorDiagnostics.INTERNAL_R0020({ message: `[vitehub] Operation ${JSON.stringify(name)} is invalid: ${reason}` });
86
+ }
87
+ function checkDefinition(definition) {
88
+ if (!isRecordOrFunction(definition)) throw invalidDefinition(void 0, "defineOperation() takes an object.");
89
+ const { name } = definition;
90
+ if (String(name) !== name || !nameFormat.test(name)) throw invalidDefinition(name, "the name must look like `section.verb`, in lower case.");
91
+ if (String(definition.description) !== definition.description || !definition.description) throw invalidDefinition(name, "add a one sentence description.");
92
+ const { section } = definition;
93
+ if (section !== false && !(section instanceof Function) && !isSectionId(section)) throw invalidDefinition(name, "section must be a Console section id, a function, or false; section ids cannot contain ':'.");
94
+ if (definition.scope !== void 0 && (!(definition.scope instanceof Function) || String(section) !== section)) throw invalidDefinition(name, "scope must be a function, and it needs a section id.");
95
+ if (!kinds.has(String(definition.kind))) throw invalidDefinition(name, "kind must be \"read\", \"write\", or \"destructive\".");
96
+ const input = definition.input;
97
+ if (!isRecordOrFunction(input) || !isRecordOrFunction(input["~standard"]) || !(input["~standard"].validate instanceof Function)) throw invalidDefinition(name, "input must be a Standard Schema, such as a valibot object.");
98
+ if (!(definition.run instanceof Function)) throw invalidDefinition(name, "run must be a function.");
99
+ const { maxRequestBytes } = definition;
100
+ if (maxRequestBytes !== void 0 && (!Number.isInteger(maxRequestBytes) || Number(maxRequestBytes) < 65536)) throw invalidDefinition(name, `maxRequestBytes can only raise the limit above ${defaultRequestBytes} bytes (64 KiB).`);
101
+ if (definition.readOnlyWhen !== void 0 && !(definition.readOnlyWhen instanceof Function)) throw invalidDefinition(name, "readOnlyWhen must be a function.");
102
+ const { mcp } = definition;
103
+ if (mcp !== void 0 && mcp !== false && (!isRecordOrFunction(mcp) || mcp.title !== void 0 && (String(mcp.title) !== mcp.title || !mcp.title) || mcp.format !== void 0 && !(mcp.format instanceof Function))) throw invalidDefinition(name, "mcp must be false, or an object with a title string and a format function.");
104
+ }
105
+ /** The default limit of a call, in bytes. */
106
+ const defaultRequestBytes = 65536;
107
+ /** Input keys that the generated CLI commands read themselves. */
108
+ const reservedOperationFlags = [
109
+ "input",
110
+ "json",
111
+ "timeout",
112
+ "url",
113
+ "yes"
114
+ ];
115
+ /**
116
+ * Define one operation. The Console, the CLI, MCP, and agent tools call the same definition. Contribute it with
117
+ * `vitehub: { operations: [{ module, export }] }` on a Vite plugin.
118
+ */
119
+ function defineOperation(definition) {
120
+ checkDefinition(definition);
121
+ const defined = {
122
+ ...definition,
123
+ input: withValibotJsonSchema(definition.input)
124
+ };
125
+ const properties = operationInputJsonSchema(defined).properties;
126
+ const clashes = isRecordOrFunction(properties) ? Object.keys(properties).filter((key) => reservedOperationFlags.includes(key)) : [];
127
+ if (clashes.length) throw invalidDefinition(definition.name, `the input key ${clashes.map((key) => JSON.stringify(key)).join(", ")} is a CLI flag of every command (${reservedOperationFlags.join(", ")}). Rename it.`);
128
+ return defined;
129
+ }
130
+ function isSectionId(section) {
131
+ return typeof section === "string" && section !== "" && !section.includes(":");
132
+ }
133
+ /** JSON Schema of the input, for CLI flags and MCP tool schemas. Falls back to an open object. */
134
+ function operationInputJsonSchema(operation) {
135
+ return standardJsonSchema(operation.input, "input") ?? { type: "object" };
136
+ }
137
+ //#endregion
138
+ //#region ../internal/src/operations.ts
139
+ /** Align rows of text cells in columns for CLI output. The last column is not padded. */
140
+ function table(rows) {
141
+ const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
142
+ return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
143
+ }
144
+ //#endregion
145
+ //#region src/operations.ts
146
+ const runtime = () => import("./operations-DwZWFIUX.js");
147
+ const id = v.pipe(v.string(), v.minLength(1));
148
+ function formatRuns({ runs }) {
149
+ if (runs.length === 0) return "No runs.\n";
150
+ return `${table([[
151
+ "RUN",
152
+ "STATUS",
153
+ "SCHEDULED AT",
154
+ "ATTEMPTS",
155
+ "ERROR"
156
+ ], ...runs.map((run) => [
157
+ run.id,
158
+ run.status,
159
+ run.scheduledAt,
160
+ String(run.attemptCount),
161
+ run.error?.message ?? "-"
162
+ ])])}\n`;
163
+ }
164
+ function formatAttempts({ attempts, run }) {
165
+ const header = `Run: ${run.id} (${run.status})\n`;
166
+ if (attempts.length === 0) return `${header}No attempts.\n`;
167
+ return `${header}${table([[
168
+ "ATTEMPT",
169
+ "STATUS",
170
+ "STARTED AT",
171
+ "COMPLETED AT",
172
+ "ERROR"
173
+ ], ...attempts.map((attempt) => [
174
+ attempt.id,
175
+ attempt.status,
176
+ attempt.startedAt,
177
+ attempt.completedAt ?? "-",
178
+ attempt.error?.message ?? "-"
179
+ ])])}\n`;
180
+ }
181
+ function formatRun({ run }) {
182
+ const started = Date.parse(run.startedAt ?? "");
183
+ const completed = Date.parse(run.completedAt ?? "");
184
+ const duration = Number.isNaN(started) || Number.isNaN(completed) ? void 0 : Math.max(0, completed - started);
185
+ const time = duration === void 0 ? "" : ` in ${duration < 1e3 ? `${duration} ms` : `${(duration / 1e3).toFixed(1)} s`}`;
186
+ return `${run.status} ${run.scheduleId}${time}${run.error ? `: ${run.error.message}` : ""}\nRun ${run.id}\nScheduled at ${run.scheduledAt}\n`;
187
+ }
188
+ function defineScheduleOperation(definition) {
189
+ return defineOperation({
190
+ ...definition,
191
+ section: "schedules",
192
+ user: false
193
+ });
194
+ }
195
+ const runs = defineScheduleOperation({
196
+ cli: {
197
+ command: "runs",
198
+ format: formatRuns,
199
+ namespace: "schedule",
200
+ positional: ["id"]
201
+ },
202
+ description: "List the recorded runs of one Schedule Definition, newest first.",
203
+ input: v.object({
204
+ id,
205
+ limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100)))
206
+ }),
207
+ kind: "read",
208
+ name: "schedule.runs",
209
+ run: async (input) => await (await runtime()).runScheduleRuns(input)
210
+ });
211
+ const attempts = defineScheduleOperation({
212
+ cli: {
213
+ command: "attempts",
214
+ format: formatAttempts,
215
+ namespace: "schedule",
216
+ positional: ["id"]
217
+ },
218
+ description: "List the attempts of one Schedule Run, oldest first.",
219
+ input: v.object({ id }),
220
+ kind: "read",
221
+ name: "schedule.attempts",
222
+ run: async (input) => await (await runtime()).runScheduleAttempts(input)
223
+ });
224
+ const run = defineScheduleOperation({
225
+ cli: {
226
+ command: "run",
227
+ format: formatRun,
228
+ namespace: "schedule",
229
+ positional: ["name"]
230
+ },
231
+ description: "Run a Static Schedule Definition now. The definition must set `manual: true`. `at` runs it as if the cron fired at that ISO 8601 date-time.",
232
+ input: v.object({
233
+ at: v.optional(v.string()),
234
+ name: id
235
+ }),
236
+ invoke: true,
237
+ kind: "write",
238
+ name: "schedule.run",
239
+ run: async (input) => await (await runtime()).runScheduleNow(input)
240
+ });
241
+ function timingOf(schedule) {
242
+ if (schedule.at) return `once at ${schedule.at}`;
243
+ return schedule.timeZone && schedule.timeZone !== "UTC" ? `${schedule.cron} (${schedule.timeZone})` : schedule.cron ?? "-";
244
+ }
245
+ function formatSchedules({ schedules }) {
246
+ if (schedules.length === 0) return "No started Schedules.\n";
247
+ return `${table([[
248
+ "ID",
249
+ "SCHEDULE",
250
+ "RUNS",
251
+ "STARTED AT"
252
+ ], ...schedules.map((schedule) => [
253
+ schedule.id,
254
+ schedule.name,
255
+ timingOf(schedule),
256
+ schedule.createdAt
257
+ ])])}\n`;
258
+ }
259
+ function formatStartedSchedule(verb) {
260
+ return ({ schedule }) => `${verb} ${schedule.id}: ${schedule.name}, ${timingOf(schedule)}\n`;
261
+ }
262
+ /**
263
+ * The `schedule.*` operations: runs, attempts, run, list, start, and cancel. The Console, `vitehub schedule`, and agents
264
+ * run them.
265
+ */
266
+ const scheduleOperations = [
267
+ runs,
268
+ attempts,
269
+ run,
270
+ defineScheduleOperation({
271
+ cli: {
272
+ command: "list",
273
+ format: formatSchedules,
274
+ namespace: "schedule",
275
+ positional: ["name"]
276
+ },
277
+ description: "List the Schedules that code started with startSchedule(), oldest first. `name` keeps the Schedules of one Definition.",
278
+ input: v.object({ name: v.optional(id) }),
279
+ kind: "read",
280
+ name: "schedule.list",
281
+ run: async (input) => await (await runtime()).runScheduleList(input)
282
+ }),
283
+ defineScheduleOperation({
284
+ cli: {
285
+ command: "start",
286
+ format: formatStartedSchedule("Started"),
287
+ namespace: "schedule",
288
+ positional: ["name"]
289
+ },
290
+ description: "Start a Schedule Definition without cron: once at `at` (ISO 8601 with a time zone), or on `cron` in `timeZone` until you cancel it. `payload` reaches the handler as `context.payload`.",
291
+ input: v.object({
292
+ at: v.optional(v.string()),
293
+ cron: v.optional(v.string()),
294
+ name: id,
295
+ payload: v.optional(v.unknown()),
296
+ timeZone: v.optional(v.string())
297
+ }),
298
+ invoke: true,
299
+ kind: "write",
300
+ name: "schedule.start",
301
+ run: async (input) => await (await runtime()).runScheduleStart(input)
302
+ }),
303
+ defineScheduleOperation({
304
+ cli: {
305
+ command: "cancel",
306
+ format: formatStartedSchedule("Cancelled"),
307
+ namespace: "schedule",
308
+ positional: ["id"]
309
+ },
310
+ description: "Cancel a started Schedule, so it does not run again.",
311
+ input: v.object({ id }),
312
+ kind: "destructive",
313
+ name: "schedule.cancel",
314
+ run: async (input) => await (await runtime()).runScheduleCancel(input)
315
+ })
316
+ ];
317
+ //#endregion
318
+ export { scheduleOperations };
package/dist/os.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ import { ErrorCatalog, Result } from "@vite-hub/runtime";
2
+ import { posix } from "node:path";
3
+ //#region src/os/errors.d.ts
4
+ /** Operating systems that `@vite-hub/schedule/os` installs timers on, as `process.platform` names them. */
5
+ type OsSchedulePlatform = "linux" | "darwin" | "win32";
6
+ /** `"user"` runs as the current user. `"system"` runs as root or SYSTEM and needs root or Administrator to install. */
7
+ type OsScheduleScope = "user" | "system";
8
+ type CommandFailed = {
9
+ command: string;
10
+ exitCode: number;
11
+ output: string;
12
+ };
13
+ type CronUnsupported = {
14
+ platform: OsSchedulePlatform;
15
+ cron: string;
16
+ reason: string;
17
+ };
18
+ type InvalidOptions = {
19
+ problem: string;
20
+ };
21
+ type NameTaken = {
22
+ platform: OsSchedulePlatform;
23
+ name: string;
24
+ scope: OsScheduleScope;
25
+ resource: string;
26
+ };
27
+ type OptionUnsupported = {
28
+ platform: OsSchedulePlatform;
29
+ option: string;
30
+ reason: string;
31
+ };
32
+ type PermissionRequired = {
33
+ scope: OsScheduleScope;
34
+ };
35
+ type PlatformUnsupported = {
36
+ platform: string;
37
+ };
38
+ type TimeZoneUnsupported = {
39
+ platform: OsSchedulePlatform;
40
+ timeZone: string;
41
+ machineTimeZone: string;
42
+ };
43
+ /** A code whose `error.data` holds the values of its message. */
44
+ type Code<TData> = {
45
+ fix: string;
46
+ why: (data: TData) => string;
47
+ data: (data: TData) => TData;
48
+ };
49
+ type OsScheduleErrorCodes = {
50
+ SCHEDULE_OS_COMMAND_FAILED: Code<CommandFailed>;
51
+ SCHEDULE_OS_CRON_UNSUPPORTED: Code<CronUnsupported>;
52
+ SCHEDULE_OS_INVALID_OPTIONS: Code<InvalidOptions>;
53
+ SCHEDULE_OS_NAME_TAKEN: Code<NameTaken>;
54
+ SCHEDULE_OS_OPTION_UNSUPPORTED: Code<OptionUnsupported>;
55
+ SCHEDULE_OS_PERMISSION_REQUIRED: Code<PermissionRequired>;
56
+ SCHEDULE_OS_PLATFORM_UNSUPPORTED: Code<PlatformUnsupported>;
57
+ SCHEDULE_OS_TIME_ZONE_UNSUPPORTED: Code<TimeZoneUnsupported>;
58
+ };
59
+ export declare const osScheduleErrors: ErrorCatalog<OsScheduleErrorCodes>;
60
+ type OsScheduleErrorCode = keyof OsScheduleErrorCodes;
61
+ //#endregion
62
+ //#region src/os/host.d.ts
63
+ interface OsScheduleStatus {
64
+ name: string;
65
+ platform: OsSchedulePlatform;
66
+ scope: OsScheduleScope;
67
+ /**
68
+ * The OS knows the timer, and ViteHub installed it in this scope. `false` for a timer, unit, plist, or task of the
69
+ * same name that ViteHub did not install: it is not this timer.
70
+ */
71
+ installed: boolean;
72
+ /** A run is in progress. */
73
+ running: boolean;
74
+ /** Start of the last run. macOS does not expose it. */
75
+ lastRunAt?: Date;
76
+ /** Exit code of the last finished run. */
77
+ lastExitCode?: number;
78
+ /** Next time the OS starts the timer. */
79
+ nextRunAt?: Date;
80
+ /** Linux user scope: whether systemd lingering is on. Without it, the timer runs only while the user has a session. */
81
+ linger?: boolean;
82
+ /** File that collects the output of each run. On Linux without `logDir`, the output goes to the journal. */
83
+ logFile?: string;
84
+ }
85
+ interface OsScheduleRemoval {
86
+ name: string;
87
+ platform: OsSchedulePlatform;
88
+ scope: OsScheduleScope;
89
+ /** Files that the uninstall deleted. */
90
+ removed: string[];
91
+ /**
92
+ * The timer or one of its files existed. `false` also when the name belongs to a timer that ViteHub did not install
93
+ * in this scope: the uninstall leaves it as it is.
94
+ */
95
+ existed: boolean;
96
+ }
97
+ //#endregion
98
+ //#region src/os/schedules.d.ts
99
+ /** Any object with `cron` and an optional `timeZone`. The result of `defineSchedule()` fits. */
100
+ interface OsScheduleTiming {
101
+ cron?: string;
102
+ /**
103
+ * IANA time zone of the cron. Without it, the cron runs in UTC, as every Schedule does. `"local"` runs it in the time
104
+ * zone of the machine.
105
+ */
106
+ timeZone?: string;
107
+ }
108
+ interface InstallOsScheduleOptions {
109
+ /** Program and arguments. The program is an absolute path on the target OS, such as `process.execPath`. */
110
+ command: readonly [string, ...string[]];
111
+ /**
112
+ * `"user"` (default): a systemd user timer, a LaunchAgent, or a task that runs as the current user while they are
113
+ * logged in. `"system"`: a system timer, a LaunchDaemon, or a task that runs as SYSTEM. It needs root or Administrator.
114
+ */
115
+ scope?: OsScheduleScope;
116
+ /** Run a missed time once after the machine wakes or boots. Defaults to `true`. macOS always does, so `false` fails there. */
117
+ catchUp?: boolean;
118
+ /** Environment variables of each run. Nothing is copied from the shell that installs the timer. */
119
+ env?: Record<string, string>;
120
+ /** Absolute working directory of each run. Defaults to the home directory, or the OS default for `"system"`. */
121
+ cwd?: string;
122
+ /**
123
+ * Absolute directory of `<name>.log`, which collects the output of each run. Defaults to the journal on Linux,
124
+ * `~/Library/Logs/<name>` on macOS, and `%LOCALAPPDATA%\<name>\Logs` on Windows (`/Library/Logs/<name>` and
125
+ * `%ProgramData%\<name>\Logs` for `"system"`).
126
+ */
127
+ logDir?: string;
128
+ /** Start each run up to this many seconds late, at random. systemd and Task Scheduler only. */
129
+ randomDelaySeconds?: number;
130
+ /** Defaults to `<name> (ViteHub schedule)`. */
131
+ description?: string;
132
+ }
133
+ interface OsScheduleTarget {
134
+ /** Defaults to `"user"`. */
135
+ scope?: OsScheduleScope;
136
+ }
137
+ interface OsScheduleUnit {
138
+ name: string;
139
+ platform: OsSchedulePlatform;
140
+ scope: OsScheduleScope;
141
+ /** Absolute paths of the files that the timer owns. `uninstallOsSchedule()` deletes them. */
142
+ files: string[];
143
+ /** `false` when everything was already up to date and the install changed nothing. */
144
+ changed: boolean;
145
+ /** Linux user scope: whether systemd lingering is on. When it is off, the timer runs only while the user has a session. */
146
+ linger?: boolean;
147
+ status(): Promise<Result<OsScheduleStatus, OsScheduleErrorCode>>;
148
+ uninstall(): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
149
+ }
150
+ //#endregion
151
+ //#region src/os.d.ts
152
+ /**
153
+ * Installs `schedule` as an OS timer named `name` that runs `options.command`: a systemd timer on Linux, a launchd job
154
+ * on macOS, or a Task Scheduler task on Windows. It runs on the Schedule's `cron` in its `timeZone`, or fails with a
155
+ * code when the OS cannot run that cron exactly. Installing the same timer again changes nothing. It fails with
156
+ * `SCHEDULE_OS_NAME_TAKEN` when the OS already has a timer of that name that ViteHub did not install in this scope.
157
+ */
158
+ export declare function installOsSchedule(name: string, schedule: OsScheduleTiming, options: InstallOsScheduleOptions): Promise<Result<OsScheduleUnit, OsScheduleErrorCode>>;
159
+ /** Reads the state of the OS timer `name`: whether it is installed and running, its last run and exit code, and its next run. */
160
+ export declare function osScheduleStatus(name: string, target?: OsScheduleTarget): Promise<Result<OsScheduleStatus, OsScheduleErrorCode>>;
161
+ /**
162
+ * Stops and removes the OS timer `name` and the files that it owns. Removing a timer that does not exist succeeds.
163
+ * A timer of the same name that ViteHub did not install in this scope stays as it is, and `existed` is `false`.
164
+ */
165
+ export declare function uninstallOsSchedule(name: string, target?: OsScheduleTarget): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
166
+ //#endregion
167
+ export type { InstallOsScheduleOptions, OsScheduleErrorCode, OsSchedulePlatform, OsScheduleRemoval, OsScheduleScope, OsScheduleStatus, OsScheduleTarget, OsScheduleTiming, OsScheduleUnit };