@celljs/ta-cron 0.0.0-stage → 4.9.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/web/index.js ADDED
@@ -0,0 +1,1953 @@
1
+ // web-src/cron-protocol.ts
2
+ var NAME = "@celljs/ta-cron";
3
+ var REPLY_TYPE = "ta-cron";
4
+ var Keys;
5
+ ((Keys) => {
6
+ Keys.TASKS = "tasks";
7
+ Keys.LATEST = "latest";
8
+ function runs(taskId) {
9
+ return `runs/${taskId}`;
10
+ }
11
+ Keys.runs = runs;
12
+ })(Keys ||= {});
13
+ var Limits;
14
+ ((Limits) => {
15
+ Limits.RUNS_KEPT = 20;
16
+ Limits.SUMMARY_MAX = 4000;
17
+ Limits.MIN_INTERVAL_MS = 60000;
18
+ Limits.RUN_TIMEOUT_MS = 30 * 60000;
19
+ Limits.GRACE_MS = 5 * 60000;
20
+ Limits.PARALLEL_RUNS = 3;
21
+ })(Limits ||= {});
22
+
23
+ // web-src/i18n.ts
24
+ var EN = {
25
+ title: "Scheduled",
26
+ cardTitle: "Next up",
27
+ cardEmpty: "Nothing scheduled",
28
+ newTask: "New task",
29
+ editTask: "Edit task",
30
+ count: "{count} tasks",
31
+ runningCount: "{count} running",
32
+ emptyTitle: "Let Ta work on a schedule",
33
+ emptyHint: "Each run is a new conversation; you get the summary.",
34
+ example1: "Sum up yesterday’s commits",
35
+ example2: "Check that CI passes",
36
+ example3: "Write the daily report",
37
+ next: "in {time}",
38
+ nextAt: "Next {time}",
39
+ running: "Running…",
40
+ paused: "Paused",
41
+ done: "Done",
42
+ runNow: "Run now",
43
+ edit: "Edit",
44
+ delete: "Delete",
45
+ confirmDelete: "Delete {name}?",
46
+ confirmDeleteMessage: "Its runs go too; their conversations stay.",
47
+ enable: "On",
48
+ prompt: "What should Ta do?",
49
+ promptPlaceholder: "For example: check whether CI on main passes; if not, find out why",
50
+ name: "Name",
51
+ namePlaceholder: "Optional",
52
+ when: "When",
53
+ repeat: "Repeat",
54
+ once: "Once",
55
+ every: "Every",
56
+ daily: "Daily",
57
+ weekdays: "Weekdays",
58
+ weekly: "Weekly",
59
+ custom: "Cron",
60
+ minutes: "minutes",
61
+ hours: "hours",
62
+ days: "days",
63
+ directory: "Directory",
64
+ notify: "Tell me",
65
+ notifyDefault: "Default",
66
+ notifyAlways: "Every run",
67
+ notifyError: "When it fails",
68
+ notifyNever: "Never",
69
+ model: "Model",
70
+ thinking: "Thinking",
71
+ more: "More",
72
+ cancel: "Cancel",
73
+ save: "Save",
74
+ create: "Create",
75
+ preview: "Next run {time}",
76
+ noNext: "No next run",
77
+ runs: "Runs",
78
+ noRuns: "No runs yet",
79
+ byHand: "by hand",
80
+ openChat: "Open conversation",
81
+ noChat: "This run has no conversation.",
82
+ success: "Done",
83
+ error: "Failed",
84
+ missed: "Missed",
85
+ interrupted: "The Ta service stopped during the run.",
86
+ timeout: "The run took too long and was stopped.",
87
+ missedText: "The Ta service was not running at its time.",
88
+ started: "Started {name}",
89
+ finished: "{name} is done",
90
+ failed: "{name} failed",
91
+ created: "Scheduled",
92
+ updated: "Updated",
93
+ enabled: "Turned on",
94
+ disabled: "Turned off",
95
+ removed: "Removed {names}",
96
+ removedNone: "Nothing removed",
97
+ noTasks: "No scheduled tasks yet. Try /loop 30m <prompt>.",
98
+ show: "Show",
99
+ failedAction: "Could not do it: {message}",
100
+ help: "Scheduled tasks",
101
+ serviceNeeded: "Scheduled tasks run in the Ta service."
102
+ };
103
+ var ZH = {
104
+ title: "定时任务",
105
+ cardTitle: "接下来",
106
+ cardEmpty: "没有排着的任务",
107
+ newTask: "新建任务",
108
+ editTask: "编辑任务",
109
+ count: "{count} 个任务",
110
+ runningCount: "{count} 个运行中",
111
+ emptyTitle: "让 Ta 按时干活",
112
+ emptyHint: "每次运行都是一个新对话,结束后给你看总结。",
113
+ example1: "汇总昨天的提交",
114
+ example2: "检查 CI 是否通过",
115
+ example3: "写今天的日报",
116
+ next: "{time}后",
117
+ nextAt: "下次 {time}",
118
+ running: "运行中…",
119
+ paused: "已暂停",
120
+ done: "已完成",
121
+ runNow: "立即运行",
122
+ edit: "编辑",
123
+ delete: "删除",
124
+ confirmDelete: "删除“{name}”?",
125
+ confirmDeleteMessage: "它的运行记录一起删除;对话保留。",
126
+ enable: "启用",
127
+ prompt: "要 Ta 做什么?",
128
+ promptPlaceholder: "例如:检查 main 分支的 CI 是否通过,没通过就查明原因",
129
+ name: "名字",
130
+ namePlaceholder: "可不填",
131
+ when: "时间",
132
+ repeat: "重复",
133
+ once: "一次",
134
+ every: "每隔",
135
+ daily: "每天",
136
+ weekdays: "工作日",
137
+ weekly: "每周",
138
+ custom: "Cron",
139
+ minutes: "分钟",
140
+ hours: "小时",
141
+ days: "天",
142
+ directory: "目录",
143
+ notify: "通知我",
144
+ notifyDefault: "默认",
145
+ notifyAlways: "每次运行",
146
+ notifyError: "失败时",
147
+ notifyNever: "不通知",
148
+ model: "模型",
149
+ thinking: "思考级别",
150
+ more: "更多",
151
+ cancel: "取消",
152
+ save: "保存",
153
+ create: "创建",
154
+ preview: "下次运行 {time}",
155
+ noNext: "没有下次运行",
156
+ runs: "运行记录",
157
+ noRuns: "还没有运行过",
158
+ byHand: "手动",
159
+ openChat: "打开对话",
160
+ noChat: "这次运行没有对话。",
161
+ success: "完成",
162
+ error: "失败",
163
+ missed: "错过",
164
+ interrupted: "Ta 服务在运行中途停止了。",
165
+ timeout: "运行时间太长,已停止。",
166
+ missedText: "到点时 Ta 服务没有运行。",
167
+ started: "已开始运行“{name}”",
168
+ finished: "“{name}”已完成",
169
+ failed: "“{name}”运行失败",
170
+ created: "已创建定时任务",
171
+ updated: "已更新",
172
+ enabled: "已启用",
173
+ disabled: "已暂停",
174
+ removed: "已删除 {names}",
175
+ removedNone: "没有删除任何任务",
176
+ noTasks: "还没有定时任务。试试 /loop 30m <要做的事>。",
177
+ show: "查看",
178
+ failedAction: "操作失败:{message}",
179
+ help: "定时任务",
180
+ serviceNeeded: "定时任务在 Ta 服务里运行。"
181
+ };
182
+ var CronWords;
183
+ ((CronWords) => {
184
+ function of(language) {
185
+ return language === "zh-CN" ? ZH : EN;
186
+ }
187
+ CronWords.of = of;
188
+ function format(text, values) {
189
+ return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
190
+ }
191
+ CronWords.format = format;
192
+ })(CronWords ||= {});
193
+
194
+ // web-src/page.ts
195
+ var pi;
196
+ var PAGE = `${NAME}/tasks`;
197
+ function bindPage(api) {
198
+ pi = api;
199
+ }
200
+ function t(key, values = {}) {
201
+ return CronWords.format(CronWords.of(pi.ui.language)[key], values);
202
+ }
203
+ function icon(name) {
204
+ return pi.ui.icons[name] ?? pi.ui.icons.Square;
205
+ }
206
+ function message(error) {
207
+ return error instanceof Error ? error.message : String(error);
208
+ }
209
+ function until(time, now = Date.now()) {
210
+ const minutes = Math.max(1, Math.round((time - now) / 60000));
211
+ const zh = pi.ui.language === "zh-CN";
212
+ const [amount, unit] = minutes < 60 ? [minutes, "minute"] : minutes < 48 * 60 ? [Math.round(minutes / 60), "hour"] : [Math.round(minutes / 1440), "day"];
213
+ if (zh) {
214
+ return `${amount} ${{ minute: "分钟", hour: "小时", day: "天" }[unit]}`;
215
+ }
216
+ return `${amount} ${unit}${amount === 1 ? "" : "s"}`;
217
+ }
218
+ function basename(path) {
219
+ return path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
220
+ }
221
+
222
+ class CronClient {
223
+ api;
224
+ state = { tasks: [], loaded: false, runs: {}, asks: 0 };
225
+ listeners = new Set;
226
+ stop;
227
+ constructor(api) {
228
+ this.api = api;
229
+ }
230
+ start() {
231
+ this.stop = this.api.storage.onChange((keys) => {
232
+ if (keys.includes(Keys.TASKS)) {
233
+ this.load();
234
+ }
235
+ for (const key of keys) {
236
+ const id = key.startsWith("runs/") ? key.slice(5) : undefined;
237
+ if (id && this.state.runs[id]) {
238
+ this.loadRuns(id);
239
+ }
240
+ }
241
+ });
242
+ this.load();
243
+ }
244
+ dispose() {
245
+ this.stop?.();
246
+ this.listeners.clear();
247
+ }
248
+ subscribe(listener) {
249
+ this.listeners.add(listener);
250
+ return () => this.listeners.delete(listener);
251
+ }
252
+ askNew() {
253
+ this.set({ asks: this.state.asks + 1 });
254
+ }
255
+ async load() {
256
+ await this.api.storage.get(Keys.TASKS).catch(() => {
257
+ return;
258
+ });
259
+ const tasks = await this.api.callHost("list");
260
+ this.set({ tasks, loaded: true });
261
+ }
262
+ async loadRuns(taskId) {
263
+ await this.api.storage.get(Keys.runs(taskId)).catch(() => {
264
+ return;
265
+ });
266
+ const runs = await this.api.callHost("runs", taskId);
267
+ this.set({ runs: { ...this.state.runs, [taskId]: runs } });
268
+ }
269
+ call(method, ...params) {
270
+ return this.api.callHost(method, ...params);
271
+ }
272
+ set(change) {
273
+ this.state = { ...this.state, ...change };
274
+ for (const listener of this.listeners) {
275
+ listener();
276
+ }
277
+ }
278
+ }
279
+ async function openRun(run) {
280
+ if (!run.sessionFile) {
281
+ pi.ui.notify(t("noChat"), "warning");
282
+ return;
283
+ }
284
+ try {
285
+ const open = (await pi.server.listSessions()).find((session) => session.sessionFile === run.sessionFile);
286
+ const sessionId = open?.sessionId ?? (await pi.server.openSession({ cwd: run.cwd, sessionFile: run.sessionFile, group: NAME })).sessionId;
287
+ await pi.switchSession(sessionId);
288
+ pi.ui.showView("");
289
+ } catch (error) {
290
+ pi.ui.notify(t("failedAction", { message: message(error) }), "error");
291
+ }
292
+ }
293
+
294
+ // web-src/react.ts
295
+ var React;
296
+ function bind(react) {
297
+ React = react;
298
+ }
299
+
300
+ // web-src/next-card.tsx
301
+ var SHOWN = 3;
302
+ function nextTasks(tasks, shown = SHOWN) {
303
+ const at = (task) => task.lastStatus === "running" ? 0 : task.nextRunAt ? new Date(task.nextRunAt).getTime() : Number.POSITIVE_INFINITY;
304
+ return tasks.filter((task) => task.lastStatus === "running" || task.enabled && task.nextRunAt).sort((a, b) => at(a) - at(b)).slice(0, shown);
305
+ }
306
+ function NextCard({ client }) {
307
+ const { tasks, loaded } = React.useSyncExternalStore((listener) => client.subscribe(listener), () => client.state);
308
+ const [now, setNow] = React.useState(Date.now());
309
+ React.useEffect(() => {
310
+ const timer = setInterval(() => setNow(Date.now()), 30000);
311
+ return () => clearInterval(timer);
312
+ }, []);
313
+ if (!loaded) {
314
+ return /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
315
+ rows: 2
316
+ });
317
+ }
318
+ const next = nextTasks(tasks);
319
+ if (next.length === 0) {
320
+ return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
321
+ title: t("cardEmpty"),
322
+ compact: true
323
+ });
324
+ }
325
+ return /* @__PURE__ */ React.createElement("div", {
326
+ className: "tcr-card"
327
+ }, next.map((task) => /* @__PURE__ */ React.createElement("button", {
328
+ key: task.id,
329
+ type: "button",
330
+ className: "tcr-card-row",
331
+ onClick: () => pi.ui.showView(PAGE)
332
+ }, /* @__PURE__ */ React.createElement("span", {
333
+ className: "tcr-card-name"
334
+ }, task.name), /* @__PURE__ */ React.createElement("span", {
335
+ className: "tcr-card-when"
336
+ }, task.lastStatus === "running" ? t("running") : t("next", { time: until(new Date(task.nextRunAt ?? now).getTime(), now) })))));
337
+ }
338
+
339
+ // web-src/notifier.ts
340
+ var FRESH_MS = 2 * 60000;
341
+ function watchRuns() {
342
+ const told = new Set;
343
+ let ready = false;
344
+ const tell = async () => {
345
+ const finished = await pi.storage.get(Keys.LATEST).catch(() => {
346
+ return;
347
+ });
348
+ const run = finished?.run;
349
+ if (!run || told.has(run.id)) {
350
+ return;
351
+ }
352
+ told.add(run.id);
353
+ const ended = run.endedAt ? new Date(run.endedAt).getTime() : 0;
354
+ if (!ready || !finished.notify || Date.now() - ended > FRESH_MS) {
355
+ return;
356
+ }
357
+ const failed = run.status !== "success";
358
+ const title = t(failed ? "failed" : "finished", { name: finished.taskName });
359
+ pi.ui.notify(title, failed ? "error" : "info");
360
+ if (typeof document !== "undefined" && document.hidden && typeof Notification !== "undefined" && Notification.permission === "granted") {
361
+ const body = (run.error ?? run.summary ?? "").split(`
362
+ `)[0].slice(0, 160);
363
+ const notice = new Notification(title, { body, tag: run.id });
364
+ notice.onclick = () => {
365
+ window.focus();
366
+ pi.ui.showView(PAGE);
367
+ notice.close();
368
+ };
369
+ }
370
+ };
371
+ tell().finally(() => {
372
+ ready = true;
373
+ });
374
+ return pi.storage.onChange((keys) => {
375
+ if (keys.includes(Keys.LATEST)) {
376
+ tell();
377
+ }
378
+ });
379
+ }
380
+
381
+ // web-src/cron-expression.ts
382
+ var FIELDS = [
383
+ { name: "minute", min: 0, max: 59 },
384
+ { name: "hour", min: 0, max: 23 },
385
+ { name: "day of month", min: 1, max: 31 },
386
+ { name: "month", min: 1, max: 12, names: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] },
387
+ { name: "day of week", min: 0, max: 7, names: ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] }
388
+ ];
389
+ var NICKNAMES = {
390
+ "@yearly": "0 0 1 1 *",
391
+ "@annually": "0 0 1 1 *",
392
+ "@monthly": "0 0 1 * *",
393
+ "@weekly": "0 0 * * 0",
394
+ "@daily": "0 0 * * *",
395
+ "@midnight": "0 0 * * *",
396
+ "@hourly": "0 * * * *"
397
+ };
398
+ var MAX_STEPS = 200000;
399
+
400
+ class CronExpression {
401
+ source;
402
+ minutes;
403
+ hours;
404
+ days;
405
+ months;
406
+ weekdays;
407
+ anyDay;
408
+ anyWeekday;
409
+ constructor(source, minutes, hours, days, months, weekdays, anyDay, anyWeekday) {
410
+ this.source = source;
411
+ this.minutes = minutes;
412
+ this.hours = hours;
413
+ this.days = days;
414
+ this.months = months;
415
+ this.weekdays = weekdays;
416
+ this.anyDay = anyDay;
417
+ this.anyWeekday = anyWeekday;
418
+ }
419
+ static parse(text) {
420
+ const source = text.trim().replace(/\s+/g, " ");
421
+ const expanded = NICKNAMES[source.toLowerCase()] ?? source;
422
+ const parts = expanded.split(" ");
423
+ if (parts.length !== 5) {
424
+ throw new Error(`A cron expression has five fields (minute hour day month weekday), or is one of ${Object.keys(NICKNAMES).join(", ")}: ${JSON.stringify(text)} has ${parts.length}.`);
425
+ }
426
+ const sets = parts.map((part, index) => CronExpression.field(part, FIELDS[index]));
427
+ const weekdays = sets[4];
428
+ if (weekdays.delete(7)) {
429
+ weekdays.add(0);
430
+ }
431
+ return new CronExpression(source, sets[0], sets[1], sets[2], sets[3], weekdays, parts[2] === "*", parts[4] === "*");
432
+ }
433
+ static isValid(text) {
434
+ try {
435
+ CronExpression.parse(text);
436
+ return true;
437
+ } catch {
438
+ return false;
439
+ }
440
+ }
441
+ static field(text, field) {
442
+ const values = new Set;
443
+ for (const item of text.toLowerCase().split(",")) {
444
+ const [range, stepText, extra] = item.split("/");
445
+ const step = stepText === undefined ? 1 : Number(stepText);
446
+ if (extra !== undefined || !Number.isInteger(step) || step < 1) {
447
+ throw new Error(`${JSON.stringify(item)} is not a valid ${field.name}: a step is a whole number from 1.`);
448
+ }
449
+ let from;
450
+ let to;
451
+ if (range === "*") {
452
+ from = field.min;
453
+ to = field.max;
454
+ } else {
455
+ const [first, last, more] = range.split("-");
456
+ if (more !== undefined) {
457
+ throw new Error(`${JSON.stringify(item)} is not a valid ${field.name}.`);
458
+ }
459
+ from = CronExpression.value(first, field);
460
+ to = last === undefined ? stepText === undefined ? from : field.max : CronExpression.value(last, field);
461
+ }
462
+ if (from > to) {
463
+ throw new Error(`${JSON.stringify(item)} is not a valid ${field.name}: the range goes backwards.`);
464
+ }
465
+ for (let value = from;value <= to; value += step) {
466
+ values.add(value);
467
+ }
468
+ }
469
+ return values;
470
+ }
471
+ static value(text, field) {
472
+ const named = field.names?.indexOf(text) ?? -1;
473
+ const value = named >= 0 ? named + (field.min === 1 ? 1 : 0) : /^\d+$/.test(text) ? Number(text) : Number.NaN;
474
+ if (!(value >= field.min && value <= field.max)) {
475
+ throw new Error(`${JSON.stringify(text)} is not a valid ${field.name}: from ${field.min} to ${field.max}.`);
476
+ }
477
+ return value;
478
+ }
479
+ next(after) {
480
+ const time = new Date(after.getTime());
481
+ time.setSeconds(0, 0);
482
+ time.setMinutes(time.getMinutes() + 1);
483
+ for (let step = 0;step < MAX_STEPS; step++) {
484
+ if (!this.months.has(time.getMonth() + 1)) {
485
+ time.setMonth(time.getMonth() + 1, 1);
486
+ time.setHours(0, 0, 0, 0);
487
+ } else if (!this.matchesDay(time)) {
488
+ time.setDate(time.getDate() + 1);
489
+ time.setHours(0, 0, 0, 0);
490
+ } else if (!this.hours.has(time.getHours())) {
491
+ time.setHours(time.getHours() + 1, 0, 0, 0);
492
+ } else if (!this.minutes.has(time.getMinutes())) {
493
+ time.setMinutes(time.getMinutes() + 1, 0, 0);
494
+ } else {
495
+ return time;
496
+ }
497
+ }
498
+ return;
499
+ }
500
+ matchesDay(time) {
501
+ const day = this.days.has(time.getDate());
502
+ const weekday = this.weekdays.has(time.getDay());
503
+ if (this.anyDay || this.anyWeekday) {
504
+ return day && weekday;
505
+ }
506
+ return day || weekday;
507
+ }
508
+ }
509
+
510
+ // web-src/schedule-util.ts
511
+ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
512
+ var UNITS = {
513
+ s: 1000,
514
+ sec: 1000,
515
+ m: 60000,
516
+ min: 60000,
517
+ h: 3600000,
518
+ hr: 3600000,
519
+ d: 86400000,
520
+ w: 7 * 86400000
521
+ };
522
+ var Duration;
523
+ ((Duration) => {
524
+ const PART = /(\d+)\s*(sec|min|hr|s|m|h|d|w)/gy;
525
+ function parse(text) {
526
+ const source = text.trim().toLowerCase();
527
+ if (!source) {
528
+ return;
529
+ }
530
+ PART.lastIndex = 0;
531
+ let total = 0;
532
+ let match;
533
+ let end = 0;
534
+ while (match = PART.exec(source)) {
535
+ total += Number(match[1]) * UNITS[match[2]];
536
+ end = PART.lastIndex;
537
+ }
538
+ return end === source.length && total > 0 ? total : undefined;
539
+ }
540
+ Duration.parse = parse;
541
+ function format(ms) {
542
+ const parts = [];
543
+ let rest = Math.round(ms / 1000);
544
+ for (const [unit, size] of [
545
+ ["d", 86400],
546
+ ["h", 3600],
547
+ ["m", 60],
548
+ ["s", 1]
549
+ ]) {
550
+ if (rest >= size) {
551
+ parts.push(`${Math.floor(rest / size)}${unit}`);
552
+ rest %= size;
553
+ }
554
+ }
555
+ return parts.join("") || "0s";
556
+ }
557
+ Duration.format = format;
558
+ })(Duration ||= {});
559
+ var EN_DAYS = ["Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"];
560
+ var ZH_DAYS = ["日", "一", "二", "三", "四", "五", "六"];
561
+ var WORDS = {
562
+ en: {
563
+ once: (time) => `Once, ${time}`,
564
+ every: (amount, unit) => amount === 1 ? `Every ${unit}` : `Every ${amount} ${unit}s`,
565
+ everyRaw: (duration) => `Every ${duration}`,
566
+ daily: (time) => `Daily at ${time}`,
567
+ weekdays: (time) => `Weekdays at ${time}`,
568
+ weekly: (day, time) => `${EN_DAYS[day]} at ${time}`,
569
+ monthly: (day, time) => `Monthly on day ${day} at ${time}`,
570
+ hourly: (minute) => minute === 0 ? "Hourly" : `Hourly at :${pad(minute)}`,
571
+ cron: (expression) => `Cron ${expression}`
572
+ },
573
+ zh: {
574
+ once: (time) => `${time} 运行一次`,
575
+ every: (amount, unit) => `每 ${amount === 1 ? "" : `${amount} `}${{ minute: "分钟", hour: "小时", day: "天" }[unit]}`.replace("每 天", "每天"),
576
+ everyRaw: (duration) => `每 ${duration}`,
577
+ daily: (time) => `每天 ${time}`,
578
+ weekdays: (time) => `工作日 ${time}`,
579
+ weekly: (day, time) => `每周${ZH_DAYS[day]} ${time}`,
580
+ monthly: (day, time) => `每月 ${day} 日 ${time}`,
581
+ hourly: (minute) => minute === 0 ? "每小时" : `每小时第 ${minute} 分`,
582
+ cron: (expression) => `cron ${expression}`
583
+ }
584
+ };
585
+ function pad(value) {
586
+ return String(value).padStart(2, "0");
587
+ }
588
+ var ScheduleUtil;
589
+ ((ScheduleUtil) => {
590
+ function check(value) {
591
+ const schedule = value ?? {};
592
+ switch (schedule.kind) {
593
+ case "once": {
594
+ const at = new Date(String(schedule.at ?? ""));
595
+ if (typeof schedule.at !== "string" || Number.isNaN(at.getTime())) {
596
+ throw new Error("A task that runs once needs `at`, a time such as 2026-11-12T09:00 (local time) or an ISO time.");
597
+ }
598
+ return { kind: "once", at: at.toISOString() };
599
+ }
600
+ case "interval": {
601
+ const every = typeof schedule.every === "string" ? schedule.every.trim() : "";
602
+ const ms = Duration.parse(every);
603
+ if (ms === undefined) {
604
+ throw new Error("An interval needs `every`, a duration such as 30m, 2h or 1d.");
605
+ }
606
+ if (ms < Limits.MIN_INTERVAL_MS) {
607
+ throw new Error(`An interval is at least 1m; ${every} is shorter.`);
608
+ }
609
+ return { kind: "interval", every: Duration.format(ms) };
610
+ }
611
+ case "cron": {
612
+ const expression = typeof schedule.expression === "string" ? schedule.expression : "";
613
+ return { kind: "cron", expression: CronExpression.parse(expression).source };
614
+ }
615
+ default:
616
+ throw new Error('A schedule is { kind: "once", at }, { kind: "interval", every } or { kind: "cron", expression }.');
617
+ }
618
+ }
619
+ ScheduleUtil.check = check;
620
+ function next(schedule, now) {
621
+ switch (schedule.kind) {
622
+ case "once": {
623
+ const at = new Date(schedule.at);
624
+ return at.getTime() > now.getTime() ? at : undefined;
625
+ }
626
+ case "interval":
627
+ return new Date(now.getTime() + (Duration.parse(schedule.every) ?? Limits.MIN_INTERVAL_MS));
628
+ case "cron":
629
+ return CronExpression.parse(schedule.expression).next(now);
630
+ }
631
+ }
632
+ ScheduleUtil.next = next;
633
+ function repeats(schedule) {
634
+ return schedule.kind !== "once";
635
+ }
636
+ ScheduleUtil.repeats = repeats;
637
+ function notifyLevel(task) {
638
+ return task.notify ?? (repeats(task.schedule) ? "error" : "always");
639
+ }
640
+ ScheduleUtil.notifyLevel = notifyLevel;
641
+ function shouldNotify(level, failed) {
642
+ return level === "always" || level === "error" && failed;
643
+ }
644
+ ScheduleUtil.shouldNotify = shouldNotify;
645
+ function clock(time, now = new Date) {
646
+ const day = `${time.getMonth() + 1}/${time.getDate()}`;
647
+ const year = time.getFullYear() === now.getFullYear() ? "" : `${time.getFullYear()}/`;
648
+ return `${year}${day} ${pad(time.getHours())}:${pad(time.getMinutes())}`;
649
+ }
650
+ ScheduleUtil.clock = clock;
651
+ function describe(schedule, language, now = new Date) {
652
+ const words = WORDS[language.startsWith("zh") ? "zh" : "en"];
653
+ switch (schedule.kind) {
654
+ case "once":
655
+ return words.once(clock(new Date(schedule.at), now));
656
+ case "interval":
657
+ return describeInterval(schedule.every, words);
658
+ case "cron":
659
+ return describeCron(schedule.expression, words);
660
+ }
661
+ }
662
+ ScheduleUtil.describe = describe;
663
+ function describeInterval(every, words) {
664
+ const ms = Duration.parse(every) ?? 0;
665
+ for (const [unit, size] of [
666
+ ["day", 86400000],
667
+ ["hour", 3600000],
668
+ ["minute", 60000]
669
+ ]) {
670
+ if (ms >= size && ms % size === 0) {
671
+ return words.every(ms / size, unit);
672
+ }
673
+ }
674
+ return words.everyRaw(every);
675
+ }
676
+ function describeCron(expression, words) {
677
+ const fields = (NICKNAMES[expression.toLowerCase()] ?? expression).split(" ");
678
+ const [minute, hour, day, month, weekday] = fields;
679
+ const number = (text) => /^\d+$/.test(text) ? Number(text) : undefined;
680
+ const m = number(minute);
681
+ const h = number(hour);
682
+ const time = m !== undefined && h !== undefined ? `${pad(h)}:${pad(m)}` : undefined;
683
+ if (month === "*") {
684
+ if (time && day === "*" && weekday === "*") {
685
+ return words.daily(time);
686
+ }
687
+ if (time && day === "*" && weekday === "1-5") {
688
+ return words.weekdays(time);
689
+ }
690
+ const d = number(weekday);
691
+ if (time && day === "*" && d !== undefined && d <= 7) {
692
+ return words.weekly(d % 7, time);
693
+ }
694
+ const date = number(day);
695
+ if (time && date !== undefined && weekday === "*") {
696
+ return words.monthly(date, time);
697
+ }
698
+ if (m !== undefined && hour === "*" && day === "*" && weekday === "*") {
699
+ return words.hourly(m);
700
+ }
701
+ const everyMinutes = /^\*\/(\d+)$/.exec(minute);
702
+ if (everyMinutes && hour === "*" && day === "*" && weekday === "*") {
703
+ return words.every(Number(everyMinutes[1]), "minute");
704
+ }
705
+ const everyHours = /^\*\/(\d+)$/.exec(hour);
706
+ if (m === 0 && everyHours && day === "*" && weekday === "*") {
707
+ return words.every(Number(everyHours[1]), "hour");
708
+ }
709
+ }
710
+ return words.cron(expression);
711
+ }
712
+ })(ScheduleUtil ||= {});
713
+
714
+ // web-src/commands.ts
715
+ var FLAG_NAMES = ["name", "notify", "model", "thinking", "cwd"];
716
+ var TRAILING_FLAG = new RegExp(`(?:^|\\s)--(${FLAG_NAMES.join("|")})(?:=|\\s+)("[^"]*"|'[^']*'|\\S*)\\s*$`);
717
+ var ACTIONS = ["add", "list", "show", "runs", "run", "enable", "disable", "set", "remove", "clear", "help"];
718
+ var HELP = `Scheduled tasks: each run is a conversation of its own in the Ta service, which runs them while it runs.
719
+
720
+ /loop <when> <prompt> repeat: 30m, 2h, @daily, @hourly, or a cron expression in quotes ("0 9 * * 1-5")
721
+ /remind in <duration> <prompt> once, after a while: in 45m
722
+ /remind at <time> <prompt> once, at a time: at 15:30, at 2026-11-12 09:00
723
+ /schedule add <when> <prompt> as /loop
724
+ /schedule list the tasks
725
+ /schedule show <task> a task and its last runs
726
+ /schedule run <task> run it now; its schedule stays
727
+ /schedule enable|disable <task>
728
+ /schedule set <task> [flags] change it; a value of - clears the flag
729
+ /schedule remove <task>
730
+ /schedule clear remove the tasks of this directory
731
+
732
+ A task is its id, the start of it, or its name. Flags at the end of a prompt:
733
+ --name <name> --notify always|error|never --model <provider/model> --thinking <level> --cwd <directory>`;
734
+ var CommandParser;
735
+ ((CommandParser) => {
736
+ function splitFlags(text) {
737
+ const flags = {};
738
+ let rest = text.trim();
739
+ for (let match = TRAILING_FLAG.exec(rest);match; match = TRAILING_FLAG.exec(rest)) {
740
+ const key = match[1];
741
+ if (flags[key] === undefined) {
742
+ flags[key] = unquote(match[2]);
743
+ }
744
+ rest = rest.slice(0, match.index).trimEnd();
745
+ }
746
+ return { rest, flags };
747
+ }
748
+ CommandParser.splitFlags = splitFlags;
749
+ function repeating(text) {
750
+ const { rest, flags } = splitFlags(text);
751
+ const { schedule, remainder } = leadingSchedule(rest);
752
+ return input(schedule, remainder, flags);
753
+ }
754
+ CommandParser.repeating = repeating;
755
+ function reminder(text, now) {
756
+ const { rest, flags } = splitFlags(text);
757
+ const words = rest.split(/\s+/);
758
+ let at;
759
+ let used = 0;
760
+ if (words[0] === "at") {
761
+ const time = clockTime(words.slice(1, 3), now);
762
+ at = time?.date;
763
+ used = 1 + (time?.words ?? 0);
764
+ } else {
765
+ const offset = words[0] === "in" ? 1 : 0;
766
+ const ms = Duration.parse(words[offset] ?? "");
767
+ at = ms === undefined ? undefined : new Date(now.getTime() + ms);
768
+ used = offset + 1;
769
+ }
770
+ if (!at) {
771
+ throw new Error("Say when: /remind in 45m <prompt>, or /remind at 15:30 <prompt>.");
772
+ }
773
+ return input({ kind: "once", at: at.toISOString() }, words.slice(used).join(" "), flags);
774
+ }
775
+ CommandParser.reminder = reminder;
776
+ function action(text) {
777
+ const trimmed = text.trim();
778
+ const first = trimmed.split(/\s+/, 1)[0] || "list";
779
+ const action2 = first === "delete" ? "remove" : first === "ls" ? "list" : first;
780
+ if (!ACTIONS.includes(action2)) {
781
+ throw new Error(`/schedule does not know ${JSON.stringify(first)}. It takes: ${ACTIONS.join(", ")}.`);
782
+ }
783
+ return { action: action2, rest: trimmed.slice(trimmed ? first.length : 0).trim() };
784
+ }
785
+ CommandParser.action = action;
786
+ function patch(text) {
787
+ const { rest, flags } = splitFlags(text);
788
+ if (!rest) {
789
+ throw new Error("Name the task: /schedule set <task> --model <provider/model>.");
790
+ }
791
+ const value = (flag) => flag === undefined ? undefined : flag === "-" ? "" : flag;
792
+ const patch2 = {};
793
+ if (flags.name !== undefined) {
794
+ patch2.name = value(flags.name);
795
+ }
796
+ if (flags.cwd !== undefined) {
797
+ patch2.cwd = value(flags.cwd);
798
+ }
799
+ if (flags.model !== undefined) {
800
+ patch2.model = value(flags.model);
801
+ }
802
+ if (flags.thinking !== undefined) {
803
+ patch2.thinking = value(flags.thinking);
804
+ }
805
+ if (flags.notify !== undefined) {
806
+ patch2.notify = value(flags.notify);
807
+ }
808
+ if (Object.keys(patch2).length === 0) {
809
+ throw new Error("Say what changes: --name, --notify, --model, --thinking or --cwd.");
810
+ }
811
+ return { ref: rest, patch: patch2 };
812
+ }
813
+ CommandParser.patch = patch;
814
+ function leadingSchedule(text) {
815
+ const trimmed = text.trim();
816
+ const quote = trimmed[0];
817
+ if (quote === '"' || quote === "'") {
818
+ const end = trimmed.indexOf(quote, 1);
819
+ if (end < 0) {
820
+ throw new Error("The cron expression has no closing quote.");
821
+ }
822
+ return { schedule: ScheduleUtil.check({ kind: "cron", expression: trimmed.slice(1, end) }), remainder: trimmed.slice(end + 1) };
823
+ }
824
+ const [first = ""] = trimmed.split(/\s+/, 1);
825
+ const remainder = trimmed.slice(first.length);
826
+ if (first.startsWith("@")) {
827
+ return { schedule: ScheduleUtil.check({ kind: "cron", expression: first }), remainder };
828
+ }
829
+ if (Duration.parse(first) !== undefined) {
830
+ return { schedule: ScheduleUtil.check({ kind: "interval", every: first }), remainder };
831
+ }
832
+ throw new Error('Start with when: 30m, 2h, @daily, or a cron expression in quotes such as "0 9 * * 1-5".');
833
+ }
834
+ CommandParser.leadingSchedule = leadingSchedule;
835
+ function clockTime(words, now) {
836
+ const [first = "", second = ""] = words;
837
+ const hm = /^(\d{1,2}):(\d{2})$/;
838
+ const day = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
839
+ const time = hm.exec(first);
840
+ if (time) {
841
+ const date2 = new Date(now.getTime());
842
+ date2.setHours(Number(time[1]), Number(time[2]), 0, 0);
843
+ if (date2.getTime() <= now.getTime()) {
844
+ date2.setDate(date2.getDate() + 1);
845
+ }
846
+ return valid(date2, Number(time[1]) < 24 && Number(time[2]) < 60) ? { date: date2, words: 1 } : undefined;
847
+ }
848
+ const date = day.exec(first);
849
+ const later = hm.exec(second);
850
+ if (date) {
851
+ const at = new Date(Number(date[1]), Number(date[2]) - 1, Number(date[3]), later ? Number(later[1]) : 9, later ? Number(later[2]) : 0);
852
+ return valid(at, true) ? { date: at, words: later ? 2 : 1 } : undefined;
853
+ }
854
+ const iso = /^\d{4}-\d{2}-\d{2}T/.test(first) ? new Date(first) : undefined;
855
+ return iso && valid(iso, true) ? { date: iso, words: 1 } : undefined;
856
+ }
857
+ CommandParser.clockTime = clockTime;
858
+ function valid(date, ok) {
859
+ return ok && !Number.isNaN(date.getTime());
860
+ }
861
+ function input(schedule, prompt, flags) {
862
+ const text = prompt.trim();
863
+ if (!text) {
864
+ throw new Error("Then say what Ta should do: the prompt of the task.");
865
+ }
866
+ return {
867
+ schedule,
868
+ prompt: text,
869
+ ...flags.name ? { name: flags.name } : {},
870
+ ...flags.cwd ? { cwd: flags.cwd } : {},
871
+ ...flags.model ? { model: flags.model } : {},
872
+ ...flags.thinking ? { thinking: flags.thinking } : {},
873
+ ...flags.notify ? { notify: flags.notify } : {}
874
+ };
875
+ }
876
+ function unquote(value) {
877
+ return /^(["']).*\1$/.test(value) ? value.slice(1, -1) : value;
878
+ }
879
+ function completions(prefix, tasks) {
880
+ const parts = prefix.split(/\s+/);
881
+ if (parts.length <= 1) {
882
+ return ACTIONS.filter((action3) => action3.startsWith(parts[0] ?? "")).map((action3) => ({ value: `${action3} `, label: action3 }));
883
+ }
884
+ const [action2, ref] = parts;
885
+ if (!["show", "runs", "run", "enable", "disable", "set", "remove"].includes(action2) || parts.length > 2) {
886
+ return [];
887
+ }
888
+ return tasks.filter((task) => task.id.startsWith(ref) || task.name.startsWith(ref)).map((task) => ({ value: `${action2} ${task.id} `, label: task.id, description: task.name }));
889
+ }
890
+ CommandParser.completions = completions;
891
+ function loopCompletions(prefix) {
892
+ if (/\s/.test(prefix)) {
893
+ return [];
894
+ }
895
+ return [...Object.keys(NICKNAMES), "5m", "30m", "1h", "1d"].filter((item) => item.startsWith(prefix)).map((item) => ({ value: `${item} `, label: item }));
896
+ }
897
+ CommandParser.loopCompletions = loopCompletions;
898
+ })(CommandParser ||= {});
899
+ var CronText;
900
+ ((CronText) => {
901
+ function task(task2, now = new Date) {
902
+ const state = !task2.enabled ? "off" : task2.lastStatus === "running" ? "running" : task2.nextRunAt ? `next ${ScheduleUtil.clock(new Date(task2.nextRunAt), now)}` : "done";
903
+ const last = task2.lastStatus && task2.lastStatus !== "running" ? `, last ${task2.lastStatus}` : "";
904
+ return `${task2.id} ${task2.name} (${ScheduleUtil.describe(task2.schedule, "en", now)}; ${state}${last}) in ${task2.cwd}`;
905
+ }
906
+ CronText.task = task;
907
+ function run(run2, now = new Date) {
908
+ const time = ScheduleUtil.clock(new Date(run2.startedAt), now);
909
+ const took = run2.endedAt ? ` in ${Duration.format(new Date(run2.endedAt).getTime() - new Date(run2.startedAt).getTime())}` : "";
910
+ const what = run2.error ?? run2.summary ?? "";
911
+ const file = run2.sessionFile ? `
912
+ conversation: ${run2.sessionFile}` : "";
913
+ return `${run2.id} ${time} ${run2.status}${took}${run2.trigger === "manual" ? " (by hand)" : ""}${what ? `
914
+ ${what.replace(/\n/g, `
915
+ `)}` : ""}${file}`;
916
+ }
917
+ CronText.run = run;
918
+ function reply(reply2) {
919
+ switch (reply2.kind) {
920
+ case "task":
921
+ return `${capital(reply2.event)}: ${task(reply2.task)}`;
922
+ case "removed":
923
+ return reply2.tasks.length ? `Removed ${reply2.tasks.map((item) => item.name).join(", ")}.` : "No tasks to remove.";
924
+ case "started":
925
+ return `Started ${reply2.task.name} (${reply2.run.id}); it runs in a conversation of its own.`;
926
+ case "list":
927
+ return reply2.tasks.length ? reply2.tasks.map((item) => task(item)).join(`
928
+ `) : "No scheduled tasks. Make one with /loop or /remind.";
929
+ case "show":
930
+ return `${task(reply2.task)}
931
+ prompt: ${reply2.task.prompt}
932
+ ${reply2.runs.length ? reply2.runs.map((item) => run(item)).join(`
933
+ `) : "No runs yet."}`;
934
+ case "help":
935
+ return HELP;
936
+ case "error":
937
+ return reply2.message;
938
+ }
939
+ }
940
+ CronText.reply = reply;
941
+ function capital(text) {
942
+ return text[0].toUpperCase() + text.slice(1);
943
+ }
944
+ })(CronText ||= {});
945
+
946
+ // web-src/reply.tsx
947
+ function TaskLine({ task }) {
948
+ const now = new Date;
949
+ return /* @__PURE__ */ React.createElement("div", {
950
+ className: "tcr-reply-task"
951
+ }, /* @__PURE__ */ React.createElement("span", {
952
+ className: "tcr-task-name"
953
+ }, task.name), /* @__PURE__ */ React.createElement("span", {
954
+ className: "tcr-chip"
955
+ }, ScheduleUtil.describe(task.schedule, pi.ui.language, now)), /* @__PURE__ */ React.createElement("span", {
956
+ className: "tcr-muted",
957
+ title: task.cwd
958
+ }, basename(task.cwd)), task.enabled && task.nextRunAt && /* @__PURE__ */ React.createElement("span", {
959
+ className: "tcr-muted"
960
+ }, t("nextAt", { time: ScheduleUtil.clock(new Date(task.nextRunAt), now) })));
961
+ }
962
+ function Card({ title, children }) {
963
+ const Alarm = icon("AlarmClock");
964
+ return /* @__PURE__ */ React.createElement("div", {
965
+ className: "tcr-reply"
966
+ }, /* @__PURE__ */ React.createElement("div", {
967
+ className: "tcr-reply-head"
968
+ }, /* @__PURE__ */ React.createElement(Alarm, {
969
+ size: 14
970
+ }), /* @__PURE__ */ React.createElement("span", null, title), /* @__PURE__ */ React.createElement("button", {
971
+ type: "button",
972
+ className: "tcr-link",
973
+ onClick: () => pi.ui.showView(PAGE)
974
+ }, t("show"))), children);
975
+ }
976
+ function ReplyMessage({ message: message2 }) {
977
+ const reply = message2.details;
978
+ if (!reply?.kind) {
979
+ return null;
980
+ }
981
+ switch (reply.kind) {
982
+ case "task":
983
+ return /* @__PURE__ */ React.createElement(Card, {
984
+ title: t(reply.event)
985
+ }, /* @__PURE__ */ React.createElement(TaskLine, {
986
+ task: reply.task
987
+ }));
988
+ case "removed":
989
+ return /* @__PURE__ */ React.createElement(Card, {
990
+ title: reply.tasks.length ? t("removed", { names: reply.tasks.map((task) => task.name).join(", ") }) : t("removedNone")
991
+ });
992
+ case "started":
993
+ return /* @__PURE__ */ React.createElement(Card, {
994
+ title: t("started", { name: reply.task.name })
995
+ });
996
+ case "list":
997
+ return /* @__PURE__ */ React.createElement(Card, {
998
+ title: reply.tasks.length ? t("count", { count: reply.tasks.length }) : t("noTasks")
999
+ }, reply.tasks.map((task) => /* @__PURE__ */ React.createElement(TaskLine, {
1000
+ key: task.id,
1001
+ task
1002
+ })));
1003
+ case "show":
1004
+ return /* @__PURE__ */ React.createElement(Card, {
1005
+ title: reply.task.name
1006
+ }, /* @__PURE__ */ React.createElement(TaskLine, {
1007
+ task: reply.task
1008
+ }), /* @__PURE__ */ React.createElement("div", {
1009
+ className: "tcr-prompt-text"
1010
+ }, reply.task.prompt));
1011
+ case "help":
1012
+ return /* @__PURE__ */ React.createElement(Card, {
1013
+ title: t("help")
1014
+ }, /* @__PURE__ */ React.createElement("pre", {
1015
+ className: "tcr-help"
1016
+ }, HELP));
1017
+ case "error":
1018
+ return /* @__PURE__ */ React.createElement("div", {
1019
+ className: "tcr-reply tcr-reply-error"
1020
+ }, reply.message);
1021
+ }
1022
+ }
1023
+
1024
+ // web-src/style.ts
1025
+ var STYLE = `
1026
+ .tcr-card { display: flex; flex-direction: column; margin: -4px -6px; }
1027
+ .tcr-card-row { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 6px; border: 0; border-radius: 8px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; }
1028
+ .tcr-card-row:hover { background: var(--ta-hover); }
1029
+ .tcr-card-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: calc(14px * var(--ta-font-scale)); }
1030
+ .tcr-card-when { flex: none; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1031
+ .tcr-page { box-sizing: border-box; width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 24px 48px; }
1032
+ .tcr-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; min-height: 32px; }
1033
+ .tcr-stat { color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); }
1034
+ /* The head: the title in the middle, the + at the right, a box of the same width on the left to keep it there. */
1035
+ .tcr-title-bar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; padding-left: 36px; }
1036
+ .tcr-button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--ta-border); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; cursor: pointer; transition: background 120ms, opacity 120ms, transform 120ms var(--ta-ease); }
1037
+ .tcr-button:hover:not(:disabled) { background: var(--ta-hover); }
1038
+ .tcr-button:active:not(:disabled) { transform: scale(.98); }
1039
+ .tcr-button:disabled { opacity: .45; cursor: default; }
1040
+ .tcr-primary { background: var(--ta-brand); border-color: var(--ta-brand); color: var(--ta-brand-text); }
1041
+ .tcr-primary:hover:not(:disabled) { background: var(--ta-brand); opacity: .88; }
1042
+ .tcr-link { align-self: flex-start; border: 0; padding: 0; background: none; color: var(--ta-link); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
1043
+ .tcr-link:hover { text-decoration: underline; }
1044
+ .tcr-icon { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 0; border-radius: 7px; background: none; color: var(--ta-muted); cursor: pointer; }
1045
+ .tcr-icon:hover { background: var(--ta-hover); color: var(--ta-text); }
1046
+ .tcr-muted { color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1047
+ .tcr-pad { padding: 6px 2px; }
1048
+ .tcr-chip { flex: none; padding: 0 7px; border-radius: 6px; background: var(--ta-chip); color: var(--ta-secondary); font-size: calc(11.5px * var(--ta-font-scale)); line-height: calc(20px * var(--ta-font-scale)); white-space: nowrap; }
1049
+ .tcr-list { display: flex; flex-direction: column; gap: 8px; }
1050
+ .tcr-task { border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-card); transition: border-color 120ms, box-shadow 160ms; animation: tcr-in 200ms var(--ta-ease) both; }
1051
+ .tcr-task:hover, .tcr-task.tcr-open { border-color: var(--ta-border); }
1052
+ .tcr-task.tcr-menu-open { position: relative; z-index: 5; }
1053
+ .tcr-task.tcr-open { box-shadow: var(--ta-shadow-pop); }
1054
+ .tcr-disabled .tcr-task-name, .tcr-disabled .tcr-chip { opacity: .55; }
1055
+ @keyframes tcr-in { from { opacity: 0; transform: translateY(4px); } }
1056
+ .tcr-task-row { display: flex; align-items: center; gap: 6px; padding: 0 8px 0 0; }
1057
+ .tcr-task-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; height: 52px; padding: 0 6px 0 16px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
1058
+ .tcr-task-name { min-width: 0; overflow: hidden; font-size: calc(14px * var(--ta-font-scale)); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
1059
+ .tcr-task-dir { flex: 1; min-width: 0; overflow: hidden; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); text-overflow: ellipsis; white-space: nowrap; }
1060
+ .tcr-task-state { flex: none; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1061
+ .tcr-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ta-border); }
1062
+ .tcr-success { background: var(--ta-green); }
1063
+ .tcr-error, .tcr-missed { background: var(--ta-red); }
1064
+ .tcr-running { background: var(--ta-blue); animation: tcr-pulse 1.2s ease-in-out infinite; }
1065
+ .tcr-off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ta-border); }
1066
+ .tcr-pulse { animation: tcr-fade 1.6s ease-in-out infinite; }
1067
+ @keyframes tcr-pulse { 50% { transform: scale(1.5); opacity: .5; } }
1068
+ @keyframes tcr-fade { 50% { opacity: .45; } }
1069
+ .tcr-switch { position: relative; flex: none; width: 30px; height: 18px; cursor: pointer; }
1070
+ .tcr-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
1071
+ .tcr-switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--ta-border); transition: background 160ms; pointer-events: none; }
1072
+ .tcr-switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 180ms var(--ta-ease); }
1073
+ .tcr-switch input:checked + span { background: var(--ta-green); }
1074
+ .tcr-switch input:checked + span::after { transform: translateX(12px); }
1075
+ .tcr-switch input:focus-visible + span { outline: 2px solid var(--ta-border-focus); outline-offset: 2px; }
1076
+ .tcr-more { position: relative; }
1077
+ .tcr-menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; min-width: 150px; padding: 4px; border: 1px solid var(--ta-border-muted); border-radius: 10px; background: var(--ta-raised); box-shadow: var(--ta-shadow-pop); animation: tcr-in 120ms var(--ta-ease); }
1078
+ .tcr-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 7px; background: none; color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
1079
+ .tcr-menu-item:hover { background: var(--ta-hover); }
1080
+ .tcr-danger { color: var(--ta-red); }
1081
+ .tcr-detail { padding: 2px 16px 14px 34px; animation: tcr-in 160ms var(--ta-ease); }
1082
+ .tcr-prompt-text { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--ta-chip); color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.55; white-space: pre-wrap; max-height: 160px; overflow: auto; }
1083
+ .tcr-label { margin: 0 0 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; }
1084
+ .tcr-run { border-radius: 8px; }
1085
+ .tcr-run.tcr-open { background: var(--ta-hover); }
1086
+ .tcr-run-head { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 8px; border: 0; border-radius: 8px; background: none; color: inherit; font: inherit; font-size: calc(13px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
1087
+ .tcr-run-head:hover { background: var(--ta-hover); }
1088
+ .tcr-run-time { flex: none; font-variant-numeric: tabular-nums; }
1089
+ .tcr-run-status { flex: none; color: var(--ta-secondary); }
1090
+ .tcr-run-line { flex: 1; min-width: 0; overflow: hidden; color: var(--ta-muted); text-overflow: ellipsis; white-space: nowrap; }
1091
+ .tcr-run-body { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 2px 10px 12px 26px; font-size: calc(13.5px * var(--ta-font-scale)); }
1092
+ .tcr-run-body > :first-child { align-self: stretch; }
1093
+ .tcr-run-error { color: var(--ta-red); white-space: pre-wrap; }
1094
+ .tcr-empty { display: flex; flex-direction: column; align-items: center; padding: 48px 0 24px; text-align: center; }
1095
+ .tcr-empty-title { margin-top: 14px; font-size: calc(17px * var(--ta-font-scale)); font-weight: 600; }
1096
+ .tcr-empty-hint { margin-top: 6px; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); }
1097
+ .tcr-clock { width: 112px; height: 112px; }
1098
+ .tcr-clock-face { fill: var(--ta-card); stroke: var(--ta-border); stroke-width: 2; }
1099
+ .tcr-clock-tick { stroke: var(--ta-muted); stroke-width: 2; stroke-linecap: round; }
1100
+ .tcr-clock-hour { stroke: var(--ta-text); stroke-width: 4; stroke-linecap: round; transform-origin: 60px 60px; transform: rotate(-60deg); }
1101
+ .tcr-clock-hand { stroke: var(--ta-green); stroke-width: 2.5; stroke-linecap: round; transform-origin: 60px 60px; animation: tcr-spin 6s steps(60) infinite; }
1102
+ .tcr-clock-pin { fill: var(--ta-green); }
1103
+ @keyframes tcr-spin { to { transform: rotate(360deg); } }
1104
+ .tcr-examples { width: 100%; max-width: 560px; margin-top: 26px; }
1105
+ @media (max-width: 640px) { .tcr-task-dir { display: none; } .tcr-page { padding: 16px 12px 40px; } }
1106
+ .tcr-form { box-sizing: border-box; display: flex; flex-direction: column; gap: 16px; width: 100%; min-height: 0; overflow-y: auto; padding: 4px 2px 2px; }
1107
+ .tcr-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
1108
+ .tcr-field .tcr-label { margin: 0; }
1109
+ .tcr-input { box-sizing: border-box; width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: var(--ta-input); color: var(--ta-text); font: inherit; font-size: calc(13.5px * var(--ta-font-scale)); outline: none; transition: border-color 120ms; }
1110
+ .tcr-input:focus { border-color: var(--ta-border-focus); }
1111
+ .tcr-prompt { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; }
1112
+ .tcr-mono { font-family: var(--ta-mono); }
1113
+ .tcr-amount { width: 90px; flex: none; }
1114
+ .tcr-row { display: flex; gap: 8px; }
1115
+ .tcr-segments { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--ta-chip); align-self: flex-start; max-width: 100%; overflow-x: auto; }
1116
+ .tcr-segment { height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(13px * var(--ta-font-scale)); white-space: nowrap; cursor: pointer; transition: background 140ms, color 140ms; }
1117
+ .tcr-segment[aria-pressed='true'] { background: var(--ta-raised); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
1118
+ .tcr-preview { color: var(--ta-green); font-size: calc(12.5px * var(--ta-font-scale)); }
1119
+ .tcr-preview.tcr-bad { color: var(--ta-red); }
1120
+ .tcr-folder { display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; }
1121
+ .tcr-folder-path { flex: 1; min-width: 0; overflow: hidden; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: right; }
1122
+ .tcr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
1123
+ .tcr-wide { grid-column: 1 / -1; }
1124
+ .tcr-actions { display: flex; justify-content: flex-end; gap: 8px; }
1125
+ .tcr-reply { margin: 4px 0; padding: 10px 12px; border: 1px solid var(--ta-border-muted); border-radius: 10px; background: var(--ta-card); font-size: calc(13px * var(--ta-font-scale)); }
1126
+ .tcr-reply-head { display: flex; align-items: center; gap: 8px; color: var(--ta-secondary); }
1127
+ .tcr-reply-head svg { color: var(--ta-green); }
1128
+ .tcr-reply-head .tcr-link { margin-left: auto; }
1129
+ .tcr-reply-task { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
1130
+ .tcr-reply .tcr-prompt-text { margin: 8px 0 0; }
1131
+ .tcr-reply-error { color: var(--ta-red); }
1132
+ .tcr-help { margin: 8px 0 0; font-family: var(--ta-mono); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.6; white-space: pre-wrap; color: var(--ta-secondary); }
1133
+ @media (prefers-reduced-motion: reduce) { .tcr-clock-hand, .tcr-running, .tcr-pulse { animation: none; } }
1134
+ `;
1135
+ function injectStyle() {
1136
+ const element = document.createElement("style");
1137
+ element.dataset.taPackage = "ta-cron";
1138
+ element.textContent = STYLE;
1139
+ document.head.appendChild(element);
1140
+ return () => element.remove();
1141
+ }
1142
+
1143
+ // web-src/form-util.ts
1144
+ function pad2(value) {
1145
+ return String(value).padStart(2, "0");
1146
+ }
1147
+ var FormUtil;
1148
+ ((FormUtil) => {
1149
+ function localTime(date) {
1150
+ return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
1151
+ }
1152
+ FormUtil.localTime = localTime;
1153
+ function empty(cwd, now) {
1154
+ const soon = new Date(now.getTime() + 60 * 60000);
1155
+ soon.setMinutes(0, 0, 0);
1156
+ return {
1157
+ prompt: "",
1158
+ name: "",
1159
+ mode: "repeat",
1160
+ repeat: "daily",
1161
+ amount: 30,
1162
+ unit: "m",
1163
+ time: "09:00",
1164
+ weekday: 1,
1165
+ cron: "0 9 * * *",
1166
+ at: localTime(soon),
1167
+ cwd,
1168
+ notify: "",
1169
+ model: "",
1170
+ thinking: ""
1171
+ };
1172
+ }
1173
+ FormUtil.empty = empty;
1174
+ function fromTask(task, now) {
1175
+ const form = {
1176
+ ...empty(task.cwd, now),
1177
+ prompt: task.prompt,
1178
+ name: task.name,
1179
+ cwd: task.cwd,
1180
+ notify: task.notify ?? "",
1181
+ model: task.model ?? "",
1182
+ thinking: task.thinking ?? ""
1183
+ };
1184
+ return { ...form, ...ruleOf(task.schedule) };
1185
+ }
1186
+ FormUtil.fromTask = fromTask;
1187
+ function ruleOf(schedule2) {
1188
+ if (schedule2.kind === "once") {
1189
+ return { mode: "once", at: localTime(new Date(schedule2.at)) };
1190
+ }
1191
+ if (schedule2.kind === "interval") {
1192
+ const ms = Duration.parse(schedule2.every) ?? 30 * 60000;
1193
+ const [amount, unit] = ms % 86400000 === 0 ? [ms / 86400000, "d"] : ms % 3600000 === 0 ? [ms / 3600000, "h"] : [Math.round(ms / 60000), "m"];
1194
+ return { mode: "repeat", repeat: "every", amount, unit };
1195
+ }
1196
+ const [minute, hour, day, month, weekday] = (NICKNAMES[schedule2.expression.toLowerCase()] ?? schedule2.expression).split(" ");
1197
+ const simple = /^\d+$/.test(minute) && /^\d+$/.test(hour) && day === "*" && month === "*";
1198
+ const time = `${pad2(Number(hour))}:${pad2(Number(minute))}`;
1199
+ if (simple && weekday === "*") {
1200
+ return { mode: "repeat", repeat: "daily", time, cron: schedule2.expression };
1201
+ }
1202
+ if (simple && weekday === "1-5") {
1203
+ return { mode: "repeat", repeat: "weekdays", time, cron: schedule2.expression };
1204
+ }
1205
+ if (simple && /^[0-7]$/.test(weekday)) {
1206
+ return { mode: "repeat", repeat: "weekly", time, weekday: Number(weekday) % 7, cron: schedule2.expression };
1207
+ }
1208
+ return { mode: "repeat", repeat: "custom", cron: schedule2.expression };
1209
+ }
1210
+ function schedule(form) {
1211
+ if (form.mode === "once") {
1212
+ return ScheduleUtil.check({ kind: "once", at: form.at });
1213
+ }
1214
+ const time = /^(\d{1,2}):(\d{2})$/.exec(form.time);
1215
+ const [hour, minute] = time ? [Number(time[1]), Number(time[2])] : [9, 0];
1216
+ switch (form.repeat) {
1217
+ case "every":
1218
+ return ScheduleUtil.check({ kind: "interval", every: `${Math.max(1, Math.floor(form.amount || 0))}${form.unit}` });
1219
+ case "daily":
1220
+ return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * *` });
1221
+ case "weekdays":
1222
+ return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * 1-5` });
1223
+ case "weekly":
1224
+ return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * ${form.weekday}` });
1225
+ case "custom":
1226
+ return ScheduleUtil.check({ kind: "cron", expression: form.cron });
1227
+ }
1228
+ }
1229
+ FormUtil.schedule = schedule;
1230
+ function preview(form, now) {
1231
+ try {
1232
+ const next = ScheduleUtil.next(schedule(form), now);
1233
+ return next ? { next } : { error: "" };
1234
+ } catch (error) {
1235
+ return { error: error instanceof Error ? error.message : String(error) };
1236
+ }
1237
+ }
1238
+ FormUtil.preview = preview;
1239
+ function input(form) {
1240
+ return {
1241
+ prompt: form.prompt,
1242
+ name: form.name.trim() || undefined,
1243
+ schedule: schedule(form),
1244
+ cwd: form.cwd || undefined,
1245
+ model: form.model || undefined,
1246
+ thinking: form.thinking || undefined,
1247
+ notify: form.notify || undefined
1248
+ };
1249
+ }
1250
+ FormUtil.input = input;
1251
+ })(FormUtil ||= {});
1252
+
1253
+ // web-src/editor.tsx
1254
+ var REPEATS = ["every", "daily", "weekdays", "weekly", "custom"];
1255
+ var UNITS2 = [
1256
+ ["m", "minutes"],
1257
+ ["h", "hours"],
1258
+ ["d", "days"]
1259
+ ];
1260
+ var NOTIFY = [
1261
+ ["", "notifyDefault"],
1262
+ ["always", "notifyAlways"],
1263
+ ["error", "notifyError"],
1264
+ ["never", "notifyNever"]
1265
+ ];
1266
+ function weekdayNames() {
1267
+ const format = new Intl.DateTimeFormat(pi.ui.language === "zh-CN" ? "zh-CN" : "en", { weekday: "short" });
1268
+ return Array.from({ length: 7 }, (_, day) => format.format(new Date(2023, 0, 1 + day)));
1269
+ }
1270
+ function Segments({ value, options, onChange }) {
1271
+ return /* @__PURE__ */ React.createElement("div", {
1272
+ className: "tcr-segments"
1273
+ }, options.map(([key, label]) => /* @__PURE__ */ React.createElement("button", {
1274
+ key,
1275
+ type: "button",
1276
+ "aria-pressed": value === key,
1277
+ className: "tcr-segment",
1278
+ onClick: () => onChange(key)
1279
+ }, label)));
1280
+ }
1281
+ function ModelFields({ form, set, cwd }) {
1282
+ return /* @__PURE__ */ React.createElement("div", {
1283
+ className: "tcr-grid"
1284
+ }, /* @__PURE__ */ React.createElement("div", {
1285
+ className: "tcr-field"
1286
+ }, /* @__PURE__ */ React.createElement("span", {
1287
+ className: "tcr-label"
1288
+ }, t("model")), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
1289
+ cwd,
1290
+ value: form.model,
1291
+ label: t("model"),
1292
+ onChange: (model) => set({ model })
1293
+ })), /* @__PURE__ */ React.createElement("label", {
1294
+ className: "tcr-field"
1295
+ }, /* @__PURE__ */ React.createElement("span", {
1296
+ className: "tcr-label"
1297
+ }, t("thinking")), /* @__PURE__ */ React.createElement("select", {
1298
+ className: "tcr-input",
1299
+ name: "thinking",
1300
+ value: form.thinking,
1301
+ onChange: (event) => set({ thinking: event.target.value })
1302
+ }, /* @__PURE__ */ React.createElement("option", {
1303
+ value: ""
1304
+ }, t("notifyDefault")), THINKING_LEVELS.map((level) => /* @__PURE__ */ React.createElement("option", {
1305
+ key: level,
1306
+ value: level
1307
+ }, level)))));
1308
+ }
1309
+ function When({ form, set }) {
1310
+ const preview = FormUtil.preview(form, new Date);
1311
+ const days = weekdayNames();
1312
+ let rule = null;
1313
+ if (form.mode === "once") {
1314
+ rule = /* @__PURE__ */ React.createElement("input", {
1315
+ className: "tcr-input",
1316
+ type: "datetime-local",
1317
+ value: form.at,
1318
+ onChange: (event) => set({ at: event.target.value })
1319
+ });
1320
+ } else if (form.repeat === "every") {
1321
+ rule = /* @__PURE__ */ React.createElement("div", {
1322
+ className: "tcr-row"
1323
+ }, /* @__PURE__ */ React.createElement("input", {
1324
+ className: "tcr-input tcr-amount",
1325
+ type: "number",
1326
+ min: 1,
1327
+ value: form.amount,
1328
+ onChange: (event) => set({ amount: Number(event.target.value) })
1329
+ }), /* @__PURE__ */ React.createElement("select", {
1330
+ className: "tcr-input",
1331
+ value: form.unit,
1332
+ onChange: (event) => set({ unit: event.target.value })
1333
+ }, UNITS2.map(([unit, word]) => /* @__PURE__ */ React.createElement("option", {
1334
+ key: unit,
1335
+ value: unit
1336
+ }, t(word)))));
1337
+ } else if (form.repeat === "custom") {
1338
+ rule = /* @__PURE__ */ React.createElement("input", {
1339
+ className: "tcr-input tcr-mono",
1340
+ value: form.cron,
1341
+ placeholder: "0 9 * * 1-5",
1342
+ onChange: (event) => set({ cron: event.target.value })
1343
+ });
1344
+ } else {
1345
+ rule = /* @__PURE__ */ React.createElement("div", {
1346
+ className: "tcr-row"
1347
+ }, form.repeat === "weekly" && /* @__PURE__ */ React.createElement("select", {
1348
+ className: "tcr-input",
1349
+ value: form.weekday,
1350
+ onChange: (event) => set({ weekday: Number(event.target.value) })
1351
+ }, days.map((day, index) => /* @__PURE__ */ React.createElement("option", {
1352
+ key: day,
1353
+ value: index
1354
+ }, day))), /* @__PURE__ */ React.createElement("input", {
1355
+ className: "tcr-input",
1356
+ type: "time",
1357
+ value: form.time,
1358
+ onChange: (event) => set({ time: event.target.value })
1359
+ }));
1360
+ }
1361
+ return /* @__PURE__ */ React.createElement("div", {
1362
+ className: "tcr-field"
1363
+ }, /* @__PURE__ */ React.createElement("div", {
1364
+ className: "tcr-label"
1365
+ }, t("when")), /* @__PURE__ */ React.createElement(Segments, {
1366
+ value: form.mode,
1367
+ options: [
1368
+ ["repeat", t("repeat")],
1369
+ ["once", t("once")]
1370
+ ],
1371
+ onChange: (mode) => set({ mode })
1372
+ }), form.mode === "repeat" && /* @__PURE__ */ React.createElement(Segments, {
1373
+ value: form.repeat,
1374
+ options: REPEATS.map((kind) => [kind, t(kind)]),
1375
+ onChange: (repeat) => set({ repeat })
1376
+ }), rule, /* @__PURE__ */ React.createElement("div", {
1377
+ className: `tcr-preview${preview.error === undefined ? "" : " tcr-bad"}`
1378
+ }, preview.next ? t("preview", { time: ScheduleUtil.clock(preview.next) }) : preview.error || t("noNext")));
1379
+ }
1380
+ function TaskEditor({ client, editing, onClose }) {
1381
+ const Dialog = pi.ui.Dialog;
1382
+ const FolderPicker = pi.ui.FolderPicker;
1383
+ const cwd = pi.ui.useCwd();
1384
+ const [form, setForm] = React.useState(() => {
1385
+ const now = new Date;
1386
+ if (editing.task) {
1387
+ return FormUtil.fromTask(editing.task, now);
1388
+ }
1389
+ const empty = FormUtil.empty(cwd, now);
1390
+ return { ...empty, prompt: editing.prompt ?? "", repeat: editing.repeat ?? empty.repeat };
1391
+ });
1392
+ const [picking, setPicking] = React.useState(false);
1393
+ const [more, setMore] = React.useState(!!(form.name && editing.task) || !!form.notify);
1394
+ const [saving, setSaving] = React.useState(false);
1395
+ const set = (change) => setForm((current) => ({ ...current, ...change }));
1396
+ const valid = form.prompt.trim().length > 0 && !!FormUtil.preview(form, new Date).next;
1397
+ const save = async () => {
1398
+ if (!valid || saving) {
1399
+ return;
1400
+ }
1401
+ setSaving(true);
1402
+ try {
1403
+ const input = FormUtil.input(form);
1404
+ if (editing.task) {
1405
+ await client.call("update", editing.task.id, { ...input, name: form.name, model: form.model, thinking: form.thinking, notify: form.notify });
1406
+ } else {
1407
+ await client.call("add", input);
1408
+ if (typeof Notification !== "undefined" && Notification.permission === "default") {
1409
+ Notification.requestPermission().catch(() => {
1410
+ return;
1411
+ });
1412
+ }
1413
+ }
1414
+ onClose();
1415
+ } catch (error) {
1416
+ pi.ui.notify(t("failedAction", { message: message(error) }), "error");
1417
+ } finally {
1418
+ setSaving(false);
1419
+ }
1420
+ };
1421
+ return /* @__PURE__ */ React.createElement(Dialog, {
1422
+ title: editing.task ? t("editTask") : t("newTask"),
1423
+ onClose
1424
+ }, /* @__PURE__ */ React.createElement("div", {
1425
+ className: "tcr-form"
1426
+ }, /* @__PURE__ */ React.createElement("label", {
1427
+ className: "tcr-field"
1428
+ }, /* @__PURE__ */ React.createElement("span", {
1429
+ className: "tcr-label"
1430
+ }, t("prompt")), /* @__PURE__ */ React.createElement("textarea", {
1431
+ className: "tcr-input tcr-prompt",
1432
+ rows: 4,
1433
+ value: form.prompt,
1434
+ placeholder: t("promptPlaceholder"),
1435
+ autoFocus: true,
1436
+ onChange: (event) => set({ prompt: event.target.value }),
1437
+ onKeyDown: (event) => (event.metaKey || event.ctrlKey) && event.key === "Enter" && void save()
1438
+ })), /* @__PURE__ */ React.createElement(When, {
1439
+ form,
1440
+ set
1441
+ }), /* @__PURE__ */ React.createElement("div", {
1442
+ className: "tcr-field"
1443
+ }, /* @__PURE__ */ React.createElement("span", {
1444
+ className: "tcr-label"
1445
+ }, t("directory")), /* @__PURE__ */ React.createElement("button", {
1446
+ type: "button",
1447
+ className: "tcr-input tcr-folder",
1448
+ title: form.cwd,
1449
+ onClick: () => setPicking(true)
1450
+ }, basename(form.cwd || cwd), /* @__PURE__ */ React.createElement("span", {
1451
+ className: "tcr-folder-path"
1452
+ }, form.cwd || cwd))), /* @__PURE__ */ React.createElement(ModelFields, {
1453
+ form,
1454
+ set,
1455
+ cwd: form.cwd || cwd
1456
+ }), more ? /* @__PURE__ */ React.createElement("div", {
1457
+ className: "tcr-grid"
1458
+ }, /* @__PURE__ */ React.createElement("label", {
1459
+ className: "tcr-field"
1460
+ }, /* @__PURE__ */ React.createElement("span", {
1461
+ className: "tcr-label"
1462
+ }, t("name")), /* @__PURE__ */ React.createElement("input", {
1463
+ className: "tcr-input",
1464
+ value: form.name,
1465
+ placeholder: t("namePlaceholder"),
1466
+ onChange: (event) => set({ name: event.target.value })
1467
+ })), /* @__PURE__ */ React.createElement("label", {
1468
+ className: "tcr-field"
1469
+ }, /* @__PURE__ */ React.createElement("span", {
1470
+ className: "tcr-label"
1471
+ }, t("notify")), /* @__PURE__ */ React.createElement("select", {
1472
+ className: "tcr-input",
1473
+ value: form.notify,
1474
+ onChange: (event) => set({ notify: event.target.value })
1475
+ }, NOTIFY.map(([level, word]) => /* @__PURE__ */ React.createElement("option", {
1476
+ key: level,
1477
+ value: level
1478
+ }, t(word)))))) : /* @__PURE__ */ React.createElement("button", {
1479
+ type: "button",
1480
+ className: "tcr-link",
1481
+ onClick: () => setMore(true)
1482
+ }, t("more")), /* @__PURE__ */ React.createElement("div", {
1483
+ className: "tcr-actions"
1484
+ }, /* @__PURE__ */ React.createElement("button", {
1485
+ type: "button",
1486
+ className: "tcr-button",
1487
+ onClick: onClose
1488
+ }, t("cancel")), /* @__PURE__ */ React.createElement("button", {
1489
+ type: "button",
1490
+ className: "tcr-button tcr-primary",
1491
+ disabled: !valid || saving,
1492
+ onClick: () => void save()
1493
+ }, editing.task ? t("save") : t("create")))), picking && /* @__PURE__ */ React.createElement(FolderPicker, {
1494
+ initial: form.cwd || cwd,
1495
+ onPick: (path) => {
1496
+ set({ cwd: path });
1497
+ setPicking(false);
1498
+ },
1499
+ onClose: () => setPicking(false)
1500
+ }));
1501
+ }
1502
+
1503
+ // web-src/pictures.tsx
1504
+ var Line = ({ x, y, w }) => /* @__PURE__ */ React.createElement("rect", {
1505
+ className: "ta-pic-line",
1506
+ x,
1507
+ y,
1508
+ width: w,
1509
+ height: "5",
1510
+ rx: "2.5"
1511
+ });
1512
+ function Clock() {
1513
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("circle", {
1514
+ className: "ta-pic-accent",
1515
+ cx: "140",
1516
+ cy: "20",
1517
+ r: "11"
1518
+ }), /* @__PURE__ */ React.createElement("path", {
1519
+ className: "ta-pic-stroke ta-pic-fine",
1520
+ d: "M140 14v6l4 2.5"
1521
+ }));
1522
+ }
1523
+ function Commits() {
1524
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("path", {
1525
+ className: "ta-pic-stroke ta-pic-thin",
1526
+ d: "M22 18v64"
1527
+ }), [24, 46, 68].map((y, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
1528
+ key: y
1529
+ }, /* @__PURE__ */ React.createElement("circle", {
1530
+ className: index === 0 ? "ta-pic-mark" : "ta-pic-dot",
1531
+ cx: "22",
1532
+ cy: y,
1533
+ r: "5"
1534
+ }), /* @__PURE__ */ React.createElement("rect", {
1535
+ className: index === 0 ? "ta-pic-accent" : "ta-pic-pane",
1536
+ x: "36",
1537
+ y: y - 8,
1538
+ width: index === 0 ? 80 : 70,
1539
+ height: "16",
1540
+ rx: "5"
1541
+ }), /* @__PURE__ */ React.createElement("rect", {
1542
+ className: index === 0 ? "ta-pic-mark ta-pic-soft" : "ta-pic-line",
1543
+ x: "44",
1544
+ y: y - 2.5,
1545
+ width: index === 0 ? 46 : 38,
1546
+ height: "5",
1547
+ rx: "2.5"
1548
+ }))), /* @__PURE__ */ React.createElement(Clock, null));
1549
+ }
1550
+ function Checks() {
1551
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, [20, 42, 64].map((y) => /* @__PURE__ */ React.createElement(React.Fragment, {
1552
+ key: y
1553
+ }, /* @__PURE__ */ React.createElement("circle", {
1554
+ className: "ta-pic-mark",
1555
+ cx: "24",
1556
+ cy: y + 6,
1557
+ r: "6"
1558
+ }), /* @__PURE__ */ React.createElement("path", {
1559
+ className: "ta-pic-tick",
1560
+ d: `M21 ${y + 6}l2.2 2.2 4-4.4`
1561
+ }), /* @__PURE__ */ React.createElement(Line, {
1562
+ x: 38,
1563
+ y: y + 3.5,
1564
+ w: y === 42 ? 52 : 68
1565
+ }))), /* @__PURE__ */ React.createElement("circle", {
1566
+ className: "ta-pic-accent",
1567
+ cx: "128",
1568
+ cy: "56",
1569
+ r: "18"
1570
+ }), /* @__PURE__ */ React.createElement("path", {
1571
+ className: "ta-pic-stroke ta-pic-fine",
1572
+ d: "M137 50.5a10 10 0 1 0 1 8.5M137.5 44.5v6.5h-6.5"
1573
+ }), /* @__PURE__ */ React.createElement(Clock, null));
1574
+ }
1575
+ function Report() {
1576
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("rect", {
1577
+ className: "ta-pic-accent",
1578
+ x: "30",
1579
+ y: "12",
1580
+ width: "84",
1581
+ height: "74",
1582
+ rx: "6"
1583
+ }), /* @__PURE__ */ React.createElement("rect", {
1584
+ className: "ta-pic-mark",
1585
+ x: "40",
1586
+ y: "22",
1587
+ width: "40",
1588
+ height: "6",
1589
+ rx: "3"
1590
+ }), [36, 46, 56, 66].map((y, index) => /* @__PURE__ */ React.createElement("rect", {
1591
+ key: y,
1592
+ className: "ta-pic-mark ta-pic-soft",
1593
+ x: "40",
1594
+ y,
1595
+ width: [62, 54, 64, 36][index],
1596
+ height: "5",
1597
+ rx: "2.5"
1598
+ })), /* @__PURE__ */ React.createElement(Clock, null));
1599
+ }
1600
+ var SHAPES = { commits: Commits, checks: Checks, report: Report };
1601
+ function ExampleArt({ picture }) {
1602
+ const Picture = pi.ui.Picture;
1603
+ const Shapes = SHAPES[picture];
1604
+ return /* @__PURE__ */ React.createElement(Picture, null, /* @__PURE__ */ React.createElement(Shapes, null));
1605
+ }
1606
+
1607
+ // web-src/tasks-view.tsx
1608
+ function useClient(client) {
1609
+ return React.useSyncExternalStore((listener) => client.subscribe(listener), () => client.state);
1610
+ }
1611
+ function useMinute() {
1612
+ const [now, setNow] = React.useState(Date.now());
1613
+ React.useEffect(() => {
1614
+ const timer = setInterval(() => setNow(Date.now()), 30000);
1615
+ return () => clearInterval(timer);
1616
+ }, []);
1617
+ return now;
1618
+ }
1619
+ async function guard(action) {
1620
+ try {
1621
+ await action();
1622
+ } catch (error) {
1623
+ pi.ui.notify(t("failedAction", { message: message(error) }), "error");
1624
+ }
1625
+ }
1626
+ function Dot({ status, enabled = true }) {
1627
+ return /* @__PURE__ */ React.createElement("span", {
1628
+ className: `tcr-dot tcr-${enabled ? status ?? "idle" : "off"}`
1629
+ });
1630
+ }
1631
+ function Clock2() {
1632
+ return /* @__PURE__ */ React.createElement("svg", {
1633
+ className: "tcr-clock",
1634
+ viewBox: "0 0 120 120",
1635
+ "aria-hidden": "true"
1636
+ }, /* @__PURE__ */ React.createElement("circle", {
1637
+ cx: "60",
1638
+ cy: "60",
1639
+ r: "44",
1640
+ className: "tcr-clock-face"
1641
+ }), Array.from({ length: 12 }, (_, hour) => /* @__PURE__ */ React.createElement("line", {
1642
+ key: hour,
1643
+ x1: "60",
1644
+ y1: "22",
1645
+ x2: "60",
1646
+ y2: hour % 3 === 0 ? 29 : 26,
1647
+ className: "tcr-clock-tick",
1648
+ transform: `rotate(${hour * 30} 60 60)`
1649
+ })), /* @__PURE__ */ React.createElement("line", {
1650
+ x1: "60",
1651
+ y1: "60",
1652
+ x2: "60",
1653
+ y2: "38",
1654
+ className: "tcr-clock-hour"
1655
+ }), /* @__PURE__ */ React.createElement("line", {
1656
+ x1: "60",
1657
+ y1: "60",
1658
+ x2: "60",
1659
+ y2: "28",
1660
+ className: "tcr-clock-hand"
1661
+ }), /* @__PURE__ */ React.createElement("circle", {
1662
+ cx: "60",
1663
+ cy: "60",
1664
+ r: "3.5",
1665
+ className: "tcr-clock-pin"
1666
+ }));
1667
+ }
1668
+ var EXAMPLES = [
1669
+ { text: "example1", repeat: "daily", rule: "0 9 * * *", picture: "commits" },
1670
+ { text: "example2", repeat: "every", rule: "30m", picture: "checks" },
1671
+ { text: "example3", repeat: "weekdays", rule: "0 18 * * 1-5", picture: "report" }
1672
+ ];
1673
+ function Empty({ onPick }) {
1674
+ const PictureCards = pi.ui.PictureCards;
1675
+ const cards = EXAMPLES.map((example) => {
1676
+ const schedule = example.repeat === "every" ? { kind: "interval", every: example.rule } : { kind: "cron", expression: example.rule };
1677
+ return {
1678
+ key: example.text,
1679
+ picture: /* @__PURE__ */ React.createElement(ExampleArt, {
1680
+ picture: example.picture
1681
+ }),
1682
+ label: t(example.text),
1683
+ hint: ScheduleUtil.describe(schedule, pi.ui.language),
1684
+ onPick: () => onPick({ prompt: t(example.text), repeat: example.repeat })
1685
+ };
1686
+ });
1687
+ return /* @__PURE__ */ React.createElement("div", {
1688
+ className: "tcr-empty"
1689
+ }, /* @__PURE__ */ React.createElement(Clock2, null), /* @__PURE__ */ React.createElement("div", {
1690
+ className: "tcr-empty-title"
1691
+ }, t("emptyTitle")), /* @__PURE__ */ React.createElement("div", {
1692
+ className: "tcr-empty-hint"
1693
+ }, t("emptyHint")), /* @__PURE__ */ React.createElement("div", {
1694
+ className: "tcr-examples"
1695
+ }, /* @__PURE__ */ React.createElement(PictureCards, {
1696
+ cards
1697
+ })));
1698
+ }
1699
+ function outcome(run) {
1700
+ if (run.status === "missed") {
1701
+ return t("missedText");
1702
+ }
1703
+ if (run.reason) {
1704
+ return t(run.reason);
1705
+ }
1706
+ return run.error ?? run.summary;
1707
+ }
1708
+ function RunRow({ run, now }) {
1709
+ const [open, setOpen] = React.useState(false);
1710
+ const Markdown = pi.ui.Markdown;
1711
+ const Open = icon("MessageSquareText");
1712
+ const took = run.endedAt ? Duration.format(Math.max(1000, new Date(run.endedAt).getTime() - new Date(run.startedAt).getTime())) : undefined;
1713
+ const text = outcome(run);
1714
+ const label = run.status === "running" ? t("running") : t(run.status);
1715
+ return /* @__PURE__ */ React.createElement("div", {
1716
+ className: `tcr-run${open ? " tcr-open" : ""}`
1717
+ }, /* @__PURE__ */ React.createElement("button", {
1718
+ type: "button",
1719
+ className: "tcr-run-head",
1720
+ onClick: () => setOpen(!open)
1721
+ }, /* @__PURE__ */ React.createElement(Dot, {
1722
+ status: run.status
1723
+ }), /* @__PURE__ */ React.createElement("span", {
1724
+ className: "tcr-run-time"
1725
+ }, ScheduleUtil.clock(new Date(run.startedAt), new Date(now))), /* @__PURE__ */ React.createElement("span", {
1726
+ className: "tcr-run-status"
1727
+ }, label), took && /* @__PURE__ */ React.createElement("span", {
1728
+ className: "tcr-muted"
1729
+ }, took), run.trigger === "manual" && /* @__PURE__ */ React.createElement("span", {
1730
+ className: "tcr-chip"
1731
+ }, t("byHand")), !open && text && /* @__PURE__ */ React.createElement("span", {
1732
+ className: "tcr-run-line"
1733
+ }, text.split(`
1734
+ `)[0])), open && /* @__PURE__ */ React.createElement("div", {
1735
+ className: "tcr-run-body"
1736
+ }, text && (run.status === "success" ? /* @__PURE__ */ React.createElement(Markdown, {
1737
+ text
1738
+ }) : /* @__PURE__ */ React.createElement("div", {
1739
+ className: "tcr-run-error"
1740
+ }, text)), run.sessionFile && /* @__PURE__ */ React.createElement("button", {
1741
+ type: "button",
1742
+ className: "tcr-button",
1743
+ onClick: () => void openRun(run)
1744
+ }, /* @__PURE__ */ React.createElement(Open, {
1745
+ size: 14
1746
+ }), t("openChat"))));
1747
+ }
1748
+ function Detail({ client, task, now }) {
1749
+ const { runs } = useClient(client);
1750
+ React.useEffect(() => {
1751
+ client.loadRuns(task.id).catch(() => {
1752
+ return;
1753
+ });
1754
+ }, [client, task.id]);
1755
+ const list = runs[task.id];
1756
+ return /* @__PURE__ */ React.createElement("div", {
1757
+ className: "tcr-detail"
1758
+ }, /* @__PURE__ */ React.createElement("div", {
1759
+ className: "tcr-prompt-text"
1760
+ }, task.prompt), /* @__PURE__ */ React.createElement("div", {
1761
+ className: "tcr-label"
1762
+ }, t("runs")), list && list.length === 0 && /* @__PURE__ */ React.createElement("div", {
1763
+ className: "tcr-muted tcr-pad"
1764
+ }, t("noRuns")), list?.map((run) => /* @__PURE__ */ React.createElement(RunRow, {
1765
+ key: run.id,
1766
+ run,
1767
+ now
1768
+ })));
1769
+ }
1770
+ function Menu({ items, onClose }) {
1771
+ const ref = React.useRef(null);
1772
+ React.useEffect(() => {
1773
+ const close = (event) => (event instanceof KeyboardEvent ? event.key === "Escape" : !ref.current?.contains(event.target)) && onClose();
1774
+ document.addEventListener("pointerdown", close, true);
1775
+ document.addEventListener("keydown", close);
1776
+ return () => {
1777
+ document.removeEventListener("pointerdown", close, true);
1778
+ document.removeEventListener("keydown", close);
1779
+ };
1780
+ }, [onClose]);
1781
+ return /* @__PURE__ */ React.createElement("div", {
1782
+ className: "tcr-menu",
1783
+ ref,
1784
+ role: "menu"
1785
+ }, items.map((item) => {
1786
+ const Icon = icon(item.icon);
1787
+ return /* @__PURE__ */ React.createElement("button", {
1788
+ key: item.key,
1789
+ type: "button",
1790
+ role: "menuitem",
1791
+ className: `tcr-menu-item${item.danger ? " tcr-danger" : ""}`,
1792
+ onClick: () => {
1793
+ onClose();
1794
+ item.run();
1795
+ }
1796
+ }, /* @__PURE__ */ React.createElement(Icon, {
1797
+ size: 14
1798
+ }), item.label);
1799
+ }));
1800
+ }
1801
+ function TaskRow({ client, task, now, onEdit }) {
1802
+ const [open, setOpen] = React.useState(false);
1803
+ const [menu, setMenu] = React.useState(false);
1804
+ const More = icon("Ellipsis");
1805
+ const running = task.lastStatus === "running";
1806
+ const state = running ? t("running") : !task.enabled ? task.nextRunAt || ScheduleUtil.repeats(task.schedule) ? t("paused") : t("done") : task.nextRunAt ? t("next", { time: until(new Date(task.nextRunAt).getTime(), now) }) : t("done");
1807
+ const remove = async () => {
1808
+ if (await pi.ui.confirm(t("confirmDelete", { name: task.name }), t("confirmDeleteMessage"), { confirmLabel: t("delete"), danger: true })) {
1809
+ await guard(() => client.call("remove", task.id));
1810
+ }
1811
+ };
1812
+ return /* @__PURE__ */ React.createElement("div", {
1813
+ className: `tcr-task${open ? " tcr-open" : ""}${menu ? " tcr-menu-open" : ""}${task.enabled ? "" : " tcr-disabled"}`
1814
+ }, /* @__PURE__ */ React.createElement("div", {
1815
+ className: "tcr-task-row"
1816
+ }, /* @__PURE__ */ React.createElement("button", {
1817
+ type: "button",
1818
+ className: "tcr-task-main",
1819
+ onClick: () => setOpen(!open),
1820
+ "aria-expanded": open
1821
+ }, /* @__PURE__ */ React.createElement(Dot, {
1822
+ status: task.lastStatus,
1823
+ enabled: task.enabled || running
1824
+ }), /* @__PURE__ */ React.createElement("span", {
1825
+ className: "tcr-task-name"
1826
+ }, task.name), /* @__PURE__ */ React.createElement("span", {
1827
+ className: "tcr-chip"
1828
+ }, ScheduleUtil.describe(task.schedule, pi.ui.language, new Date(now))), /* @__PURE__ */ React.createElement("span", {
1829
+ className: "tcr-task-dir",
1830
+ title: task.cwd
1831
+ }, basename(task.cwd)), /* @__PURE__ */ React.createElement("span", {
1832
+ className: `tcr-task-state${running ? " tcr-pulse" : ""}`,
1833
+ title: task.nextRunAt ? t("nextAt", { time: ScheduleUtil.clock(new Date(task.nextRunAt)) }) : undefined
1834
+ }, state)), /* @__PURE__ */ React.createElement("label", {
1835
+ className: "tcr-switch",
1836
+ title: t("enable")
1837
+ }, /* @__PURE__ */ React.createElement("input", {
1838
+ type: "checkbox",
1839
+ checked: task.enabled,
1840
+ onChange: (event) => void guard(() => client.call("setEnabled", task.id, event.target.checked))
1841
+ }), /* @__PURE__ */ React.createElement("span", null)), /* @__PURE__ */ React.createElement("div", {
1842
+ className: "tcr-more"
1843
+ }, /* @__PURE__ */ React.createElement("button", {
1844
+ type: "button",
1845
+ className: "tcr-icon",
1846
+ "aria-label": t("more"),
1847
+ onClick: () => setMenu(!menu)
1848
+ }, /* @__PURE__ */ React.createElement(More, {
1849
+ size: 16
1850
+ })), menu && /* @__PURE__ */ React.createElement(Menu, {
1851
+ onClose: () => setMenu(false),
1852
+ items: [
1853
+ { key: "run", label: t("runNow"), icon: "Play", run: () => void guard(() => client.call("run", task.id)) },
1854
+ { key: "edit", label: t("edit"), icon: "Pencil", run: () => onEdit(task) },
1855
+ { key: "delete", label: t("delete"), icon: "Trash2", danger: true, run: () => void remove() }
1856
+ ]
1857
+ }))), open && /* @__PURE__ */ React.createElement(Detail, {
1858
+ client,
1859
+ task,
1860
+ now
1861
+ }));
1862
+ }
1863
+ function TasksHead({ client }) {
1864
+ const Plus = icon("Plus");
1865
+ return /* @__PURE__ */ React.createElement("div", {
1866
+ className: "tcr-title-bar"
1867
+ }, /* @__PURE__ */ React.createElement("div", {
1868
+ className: "ta-main-title"
1869
+ }, /* @__PURE__ */ React.createElement("span", null, t("title"))), /* @__PURE__ */ React.createElement("button", {
1870
+ type: "button",
1871
+ className: "ta-icon-button tcr-new",
1872
+ title: t("newTask"),
1873
+ "aria-label": t("newTask"),
1874
+ onClick: () => client.askNew()
1875
+ }, /* @__PURE__ */ React.createElement(Plus, {
1876
+ size: 18
1877
+ })));
1878
+ }
1879
+ function TasksPage({ client }) {
1880
+ const { tasks, loaded, asks } = useClient(client);
1881
+ const now = useMinute();
1882
+ const [editing, setEditing] = React.useState();
1883
+ React.useEffect(() => {
1884
+ if (asks > 0) {
1885
+ setEditing({});
1886
+ }
1887
+ }, [asks]);
1888
+ const running = tasks.filter((task) => task.lastStatus === "running").length;
1889
+ const sorted = [...tasks].sort((a, b) => Number(b.enabled) - Number(a.enabled) || (a.nextRunAt ?? "~").localeCompare(b.nextRunAt ?? "~"));
1890
+ return /* @__PURE__ */ React.createElement("div", {
1891
+ className: "tcr-page"
1892
+ }, tasks.length > 0 && /* @__PURE__ */ React.createElement("div", {
1893
+ className: "tcr-head"
1894
+ }, /* @__PURE__ */ React.createElement("div", {
1895
+ className: "tcr-stat"
1896
+ }, t("count", { count: tasks.length }), running > 0 && /* @__PURE__ */ React.createElement("span", {
1897
+ className: "tcr-pulse"
1898
+ }, " · ", t("runningCount", { count: running })))), loaded && tasks.length === 0 && /* @__PURE__ */ React.createElement(Empty, {
1899
+ onPick: setEditing
1900
+ }), /* @__PURE__ */ React.createElement("div", {
1901
+ className: "tcr-list"
1902
+ }, sorted.map((task) => /* @__PURE__ */ React.createElement(TaskRow, {
1903
+ key: task.id,
1904
+ client,
1905
+ task,
1906
+ now,
1907
+ onEdit: (item) => setEditing({ task: item })
1908
+ }))), editing && /* @__PURE__ */ React.createElement(TaskEditor, {
1909
+ client,
1910
+ editing,
1911
+ onClose: () => setEditing(undefined)
1912
+ }));
1913
+ }
1914
+
1915
+ // web-src/index.tsx
1916
+ function activate(pi2) {
1917
+ bind(pi2.React);
1918
+ bindPage(pi2);
1919
+ const removeStyle = injectStyle();
1920
+ const client = new CronClient(pi2);
1921
+ client.start();
1922
+ pi2.registerView("tasks", {
1923
+ title: () => t("title"),
1924
+ icon: icon("AlarmClock"),
1925
+ head: () => /* @__PURE__ */ React.createElement(TasksHead, {
1926
+ client
1927
+ }),
1928
+ render: () => /* @__PURE__ */ React.createElement(TasksPage, {
1929
+ client
1930
+ }),
1931
+ order: 70,
1932
+ discover: true
1933
+ });
1934
+ pi2.registerView("next", {
1935
+ title: () => t("cardTitle"),
1936
+ icon: icon("AlarmClock"),
1937
+ location: "board",
1938
+ order: 20,
1939
+ render: () => /* @__PURE__ */ React.createElement(NextCard, {
1940
+ client
1941
+ })
1942
+ });
1943
+ pi2.registerMessageRenderer(REPLY_TYPE, ReplyMessage);
1944
+ const stopWatching = watchRuns();
1945
+ return () => {
1946
+ stopWatching();
1947
+ client.dispose();
1948
+ removeStyle();
1949
+ };
1950
+ }
1951
+ export {
1952
+ activate as default
1953
+ };