@celljs/ta-cron 4.16.0 → 4.18.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 CHANGED
@@ -17,10 +17,16 @@ var Limits;
17
17
  Limits.RUNS_KEPT = 20;
18
18
  Limits.SUMMARY_MAX = 4000;
19
19
  Limits.MIN_INTERVAL_MS = 60000;
20
+ Limits.WATCH_QUIET_MS = 5000;
21
+ Limits.EVENT_FILES = 30;
22
+ Limits.EVENT_MAX = 4000;
20
23
  Limits.RUN_TIMEOUT_MS = 30 * 60000;
24
+ Limits.WRAP_UP_MS = 10 * 60000;
21
25
  Limits.RUN_TIMEOUT_MIN_MS = 5 * 60000;
22
26
  Limits.RUN_TIMEOUT_MAX_MS = 4 * 60 * 60000;
23
27
  Limits.GRACE_MS = 5 * 60000;
28
+ Limits.RESUME_WAIT_MS = 2 * 60000;
29
+ Limits.RAN_SAVE_MS = 60000;
24
30
  Limits.PARALLEL_RUNS = 3;
25
31
  })(Limits ||= {});
26
32
 
@@ -71,8 +77,6 @@ var EN = {
71
77
  newTask: "New task",
72
78
  editTask: "Edit task",
73
79
  count: "{count} tasks",
74
- runningCount: "{count} running",
75
- offGroup: "Off",
76
80
  emptyTitle: "Let Ta work on a schedule",
77
81
  emptyHint: "Each run is a new conversation; you get the summary.",
78
82
  example1: "Sum up yesterday’s commits",
@@ -98,8 +102,6 @@ var EN = {
98
102
  every: "Every",
99
103
  daily: "Daily",
100
104
  weekdays: "Weekdays",
101
- weekly: "Weekly",
102
- custom: "Cron",
103
105
  minutes: "minutes",
104
106
  hours: "hours",
105
107
  days: "days",
@@ -115,11 +117,23 @@ var EN = {
115
117
  cancel: "Cancel",
116
118
  save: "Save",
117
119
  create: "Create",
118
- preview: "Next run {time}",
120
+ preview: "Next {time}",
119
121
  noNext: "No next run",
120
122
  runs: "Runs",
121
123
  noRuns: "No runs yet",
122
124
  byHand: "by hand",
125
+ onWatch: "Files change",
126
+ onWebhook: "Webhook",
127
+ watchPath: "Folder or file to watch",
128
+ watchPlaceholder: ". (the whole directory), src, or an absolute path",
129
+ watchHint: "Runs once files rest for 5 seconds, told which changed",
130
+ webhookHint: "After saving, copy its address from the task",
131
+ byEvent: "by event",
132
+ waitingEvent: "Waiting",
133
+ webhookLabel: "Webhook",
134
+ webhookNote: "A POST to this address on this computer runs the task; what it sends is told to the run. Anyone with the address can run it.",
135
+ copy: "Copy",
136
+ copied: "Copied",
123
137
  openChat: "Open conversation",
124
138
  noChat: "This run has no conversation.",
125
139
  success: "Done",
@@ -143,7 +157,6 @@ var EN = {
143
157
  help: "Scheduled tasks",
144
158
  serviceNeeded: "Scheduled tasks run in the Ta service.",
145
159
  makeExtension: "Make an extension",
146
- makeExtensionHint: "Ta makes a page of its own for what this task finds",
147
160
  extensionAsk: 'Make the scheduled task "{name}" an extension that shows its results',
148
161
  change: "Ask Ta to change",
149
162
  changeTitle: 'Ask Ta to change "{name}"',
@@ -158,8 +171,35 @@ var EN = {
158
171
  moreOptions: "More options",
159
172
  shortcut: "{key} + Enter to {action}",
160
173
  modelFailed: "The model for making extensions ({model}) cannot be used, so the default one is: {message}",
174
+ filterOn: "On",
175
+ filterFailed: "Failed",
176
+ filterOff: "Off",
177
+ groupRunning: "Running",
178
+ groupToday: "Today",
179
+ groupTomorrow: "Tomorrow",
180
+ groupWeek: "This week",
181
+ groupLater: "Later",
182
+ groupEvent: "When something happens",
183
+ groupDone: "No next run",
184
+ tomorrowAt: "Tomorrow {time}",
185
+ lastFailed: "Failed {time}",
186
+ factNext: "Next",
187
+ factDir: "In",
188
+ factTimeout: "Up to",
189
+ noneFailed: "No task failed its last run",
190
+ noneOff: "No task is off",
191
+ noneOn: "No task is on",
192
+ atTimes: "At times",
193
+ atTime: "Time",
194
+ useCron: "Use a cron expression",
195
+ useDays: "Pick days instead",
196
+ timeoutLabel: "A run takes at most",
197
+ timeoutDefault: "Default (30 minutes)",
198
+ timeoutIs: "up to {time}",
199
+ pickDays: "Pick a day at least",
161
200
  toolAdd: "Schedule",
162
201
  toolUpdate: "Change scheduled task",
202
+ toolPreview: "Check the time of",
163
203
  toolList: "List scheduled tasks",
164
204
  toolShow: "Look at scheduled task",
165
205
  toolEnable: "Turn on scheduled task",
@@ -177,8 +217,6 @@ var ZH = {
177
217
  newTask: "新建任务",
178
218
  editTask: "编辑任务",
179
219
  count: "{count} 个任务",
180
- runningCount: "{count} 个运行中",
181
- offGroup: "已停用",
182
220
  emptyTitle: "让 Ta 按时干活",
183
221
  emptyHint: "每次运行都是一个新对话,结束后给你看总结。",
184
222
  example1: "汇总昨天的提交",
@@ -204,8 +242,6 @@ var ZH = {
204
242
  every: "每隔",
205
243
  daily: "每天",
206
244
  weekdays: "工作日",
207
- weekly: "每周",
208
- custom: "Cron",
209
245
  minutes: "分钟",
210
246
  hours: "小时",
211
247
  days: "天",
@@ -221,11 +257,23 @@ var ZH = {
221
257
  cancel: "取消",
222
258
  save: "保存",
223
259
  create: "创建",
224
- preview: "下次运行 {time}",
260
+ preview: "接下来 {time}",
225
261
  noNext: "没有下次运行",
226
262
  runs: "运行记录",
227
263
  noRuns: "还没有运行过",
228
264
  byHand: "手动",
265
+ onWatch: "文件变化",
266
+ onWebhook: "Webhook",
267
+ watchPath: "要监听的文件夹或文件",
268
+ watchPlaceholder: ".(整个目录)、src,或绝对路径",
269
+ watchHint: "文件停下 5 秒后运行,并告诉 Ta 改了哪些文件",
270
+ webhookHint: "保存后,在任务里复制它的地址",
271
+ byEvent: "事件触发",
272
+ waitingEvent: "等待触发",
273
+ webhookLabel: "Webhook",
274
+ webhookNote: "在这台电脑上向这个地址发 POST 就会运行任务,发送的内容会告诉这次运行。拿到地址的人都能触发它。",
275
+ copy: "复制",
276
+ copied: "已复制",
229
277
  openChat: "打开对话",
230
278
  noChat: "这次运行没有对话。",
231
279
  success: "完成",
@@ -249,7 +297,6 @@ var ZH = {
249
297
  help: "定时任务",
250
298
  serviceNeeded: "定时任务在 Ta 服务里运行。",
251
299
  makeExtension: "做成扩展",
252
- makeExtensionHint: "让 Ta 为这个任务的结果做一个专属页面",
253
300
  extensionAsk: "把定时任务“{name}”做成扩展,用专属页面呈现它的运行结果",
254
301
  change: "让 Ta 改",
255
302
  changeTitle: "让 Ta 修改“{name}”",
@@ -264,8 +311,35 @@ var ZH = {
264
311
  moreOptions: "更多选项",
265
312
  shortcut: "{key} + 回车{action}",
266
313
  modelFailed: "做扩展的模型({model})现在用不了,已改用默认模型:{message}",
314
+ filterOn: "已启用",
315
+ filterFailed: "失败",
316
+ filterOff: "已停用",
317
+ groupRunning: "运行中",
318
+ groupToday: "今天",
319
+ groupTomorrow: "明天",
320
+ groupWeek: "本周",
321
+ groupLater: "以后",
322
+ groupEvent: "等待触发",
323
+ groupDone: "没有下次运行",
324
+ tomorrowAt: "明天 {time}",
325
+ lastFailed: "上次失败 {time}",
326
+ factNext: "下次",
327
+ factDir: "目录",
328
+ factTimeout: "最长",
329
+ noneFailed: "没有失败的任务",
330
+ noneOff: "没有停用的任务",
331
+ noneOn: "没有启用的任务",
332
+ atTimes: "定时",
333
+ atTime: "时间",
334
+ useCron: "改用 Cron 表达式",
335
+ useDays: "改为按星期选",
336
+ timeoutLabel: "每次最长运行",
337
+ timeoutDefault: "默认(30 分钟)",
338
+ timeoutIs: "最长 {time}",
339
+ pickDays: "至少选一天",
267
340
  toolAdd: "新建定时任务",
268
341
  toolUpdate: "修改定时任务",
342
+ toolPreview: "检查运行时间",
269
343
  toolList: "查看定时任务",
270
344
  toolShow: "查看定时任务",
271
345
  toolEnable: "开启定时任务",
@@ -283,8 +357,6 @@ var ZH_TW = {
283
357
  newTask: "新建任務",
284
358
  editTask: "編輯任務",
285
359
  count: "{count} 個任務",
286
- runningCount: "{count} 個執行中",
287
- offGroup: "已停用",
288
360
  emptyTitle: "讓 Ta 按時幹活",
289
361
  emptyHint: "每次執行都是一個新對話,結束後給你看總結。",
290
362
  example1: "彙總昨天的提交",
@@ -310,8 +382,6 @@ var ZH_TW = {
310
382
  every: "每隔",
311
383
  daily: "每天",
312
384
  weekdays: "工作日",
313
- weekly: "每週",
314
- custom: "Cron",
315
385
  minutes: "分鐘",
316
386
  hours: "小時",
317
387
  days: "天",
@@ -327,11 +397,23 @@ var ZH_TW = {
327
397
  cancel: "取消",
328
398
  save: "儲存",
329
399
  create: "建立",
330
- preview: "下次執行 {time}",
400
+ preview: "接下來 {time}",
331
401
  noNext: "沒有下次執行",
332
402
  runs: "執行記錄",
333
403
  noRuns: "還沒有執行過",
334
404
  byHand: "手動",
405
+ onWatch: "檔案變化",
406
+ onWebhook: "Webhook",
407
+ watchPath: "要監聽的資料夾或檔案",
408
+ watchPlaceholder: ".(整個目錄)、src,或絕對路徑",
409
+ watchHint: "檔案停下 5 秒後執行,並告訴 Ta 改了哪些檔案",
410
+ webhookHint: "儲存後,在任務裡複製它的位址",
411
+ byEvent: "事件觸發",
412
+ waitingEvent: "等待觸發",
413
+ webhookLabel: "Webhook",
414
+ webhookNote: "在這台電腦上向這個位址發 POST 就會執行任務,傳送的內容會告訴這次執行。拿到位址的人都能觸發它。",
415
+ copy: "複製",
416
+ copied: "已複製",
335
417
  openChat: "開啟對話",
336
418
  noChat: "這次執行沒有對話。",
337
419
  success: "完成",
@@ -355,7 +437,6 @@ var ZH_TW = {
355
437
  help: "定時任務",
356
438
  serviceNeeded: "定時任務在 Ta 服務裡執行。",
357
439
  makeExtension: "做成擴充功能",
358
- makeExtensionHint: "讓 Ta 為這個任務的結果做一個專屬頁面",
359
440
  extensionAsk: "把定時任務「{name}」做成擴充功能,用專屬頁面呈現它的執行結果",
360
441
  change: "讓 Ta 改",
361
442
  changeTitle: "讓 Ta 修改「{name}」",
@@ -370,8 +451,35 @@ var ZH_TW = {
370
451
  moreOptions: "更多選項",
371
452
  shortcut: "{key} + 回車{action}",
372
453
  modelFailed: "做擴充功能的模型({model})現在用不了,已改用預設模型:{message}",
454
+ filterOn: "已啟用",
455
+ filterFailed: "失敗",
456
+ filterOff: "已停用",
457
+ groupRunning: "執行中",
458
+ groupToday: "今天",
459
+ groupTomorrow: "明天",
460
+ groupWeek: "本週",
461
+ groupLater: "以後",
462
+ groupEvent: "等待觸發",
463
+ groupDone: "沒有下次執行",
464
+ tomorrowAt: "明天 {time}",
465
+ lastFailed: "上次失敗 {time}",
466
+ factNext: "下次",
467
+ factDir: "目錄",
468
+ factTimeout: "最長",
469
+ noneFailed: "沒有失敗的任務",
470
+ noneOff: "沒有停用的任務",
471
+ noneOn: "沒有啟用的任務",
472
+ atTimes: "定時",
473
+ atTime: "時間",
474
+ useCron: "改用 Cron 表達式",
475
+ useDays: "改為按星期選",
476
+ timeoutLabel: "每次最長執行",
477
+ timeoutDefault: "預設(30 分鐘)",
478
+ timeoutIs: "最長 {time}",
479
+ pickDays: "至少選一天",
373
480
  toolAdd: "新建定時任務",
374
481
  toolUpdate: "修改定時任務",
482
+ toolPreview: "檢查執行時間",
375
483
  toolList: "檢視定時任務",
376
484
  toolShow: "檢視定時任務",
377
485
  toolEnable: "開啟定時任務",
@@ -389,8 +497,6 @@ var JA = {
389
497
  newTask: "新しいタスク",
390
498
  editTask: "タスクを編集",
391
499
  count: "{count} 個のタスク",
392
- runningCount: "{count} 個実行中",
393
- offGroup: "オフ",
394
500
  emptyTitle: "Ta にスケジュールに従って作業させる",
395
501
  emptyHint: "各実行は新しい会話です。実行終了後にサマリーを表示します。",
396
502
  example1: "yesterday のコミットをまとめる",
@@ -416,8 +522,6 @@ var JA = {
416
522
  every: "ごと",
417
523
  daily: "毎日",
418
524
  weekdays: "平日",
419
- weekly: "毎週",
420
- custom: "Cron",
421
525
  minutes: "分",
422
526
  hours: "時間",
423
527
  days: "日",
@@ -433,11 +537,23 @@ var JA = {
433
537
  cancel: "キャンセル",
434
538
  save: "保存",
435
539
  create: "作成",
436
- preview: "次回実行 {time}",
540
+ preview: "次回 {time}",
437
541
  noNext: "次回実行なし",
438
542
  runs: "実行",
439
543
  noRuns: "まだ実行がありません",
440
544
  byHand: "手動",
545
+ onWatch: "ファイル変更",
546
+ onWebhook: "Webhook",
547
+ watchPath: "監視するフォルダーまたはファイル",
548
+ watchPlaceholder: ".(ディレクトリ全体)、src、または絶対パス",
549
+ watchHint: "ファイルが 5 秒止まったら実行し、変更されたファイルを Ta に伝えます",
550
+ webhookHint: "保存後、タスクからアドレスをコピーします",
551
+ byEvent: "イベント",
552
+ waitingEvent: "待機中",
553
+ webhookLabel: "Webhook",
554
+ webhookNote: "このコンピューターでこのアドレスに POST するとタスクが実行され、送った内容が実行に伝わります。アドレスを知っている人は誰でも実行できます。",
555
+ copy: "コピー",
556
+ copied: "コピーしました",
441
557
  openChat: "会話を開く",
442
558
  noChat: "この実行には会話がありません。",
443
559
  success: "完了",
@@ -461,7 +577,6 @@ var JA = {
461
577
  help: "スケジュールされたタスク",
462
578
  serviceNeeded: "スケジュールされたタスクは Ta サービスで実行します。",
463
579
  makeExtension: "拡張機能を作成",
464
- makeExtensionHint: "このタスクの結果用に Ta が独自のページを作成します",
465
580
  extensionAsk: "スケジュールされたタスク「{name}」を拡張機能にして、その結果を表示するページを作成します",
466
581
  change: "Ta に変更させる",
467
582
  changeTitle: "「{name}」を Ta に変更させる",
@@ -476,8 +591,35 @@ var JA = {
476
591
  moreOptions: "その他のオプション",
477
592
  shortcut: "{key} + Enter で {action}",
478
593
  modelFailed: "拡張機能を作成するモデル({model})は現在使用できません。デフォルトモデルに変更しました:{message}",
594
+ filterOn: "オン",
595
+ filterFailed: "失敗",
596
+ filterOff: "オフ",
597
+ groupRunning: "実行中",
598
+ groupToday: "今日",
599
+ groupTomorrow: "明日",
600
+ groupWeek: "今週",
601
+ groupLater: "それ以降",
602
+ groupEvent: "トリガー待ち",
603
+ groupDone: "次回なし",
604
+ tomorrowAt: "明日 {time}",
605
+ lastFailed: "前回失敗 {time}",
606
+ factNext: "次回",
607
+ factDir: "場所",
608
+ factTimeout: "最長",
609
+ noneFailed: "失敗したタスクはありません",
610
+ noneOff: "オフのタスクはありません",
611
+ noneOn: "オンのタスクはありません",
612
+ atTimes: "時刻",
613
+ atTime: "時刻",
614
+ useCron: "Cron 式を使う",
615
+ useDays: "曜日で選ぶ",
616
+ timeoutLabel: "1 回の最長実行時間",
617
+ timeoutDefault: "デフォルト(30 分)",
618
+ timeoutIs: "最長 {time}",
619
+ pickDays: "1 日以上選んでください",
479
620
  toolAdd: "スケジュール",
480
621
  toolUpdate: "スケジュールされたタスクを変更",
622
+ toolPreview: "実行時刻を確認",
481
623
  toolList: "スケジュールされたタスクを一覧表示",
482
624
  toolShow: "スケジュールされたタスクを表示",
483
625
  toolEnable: "スケジュールされたタスクをオンにする",
@@ -518,6 +660,44 @@ var NICKNAMES = {
518
660
  "@midnight": "0 0 * * *",
519
661
  "@hourly": "0 * * * *"
520
662
  };
663
+ var DAY_NAMES = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
664
+ var WeekDays;
665
+ ((WeekDays) => {
666
+ WeekDays.NAMES = DAY_NAMES;
667
+ function of(field2) {
668
+ if (field2 === "*") {
669
+ return [0, 1, 2, 3, 4, 5, 6];
670
+ }
671
+ const day = (text) => {
672
+ const index = DAY_NAMES.indexOf(text.toLowerCase());
673
+ const value = index >= 0 ? index : /^\d$/.test(text) ? Number(text) : Number.NaN;
674
+ return value >= 0 && value <= 7 ? value % 7 : undefined;
675
+ };
676
+ const days = new Set;
677
+ for (const part of field2.split(",")) {
678
+ const [from, to, extra] = part.split("-");
679
+ const start = day(from ?? "");
680
+ const end = to === undefined ? start : day(to);
681
+ if (start === undefined || end === undefined || extra !== undefined) {
682
+ return;
683
+ }
684
+ const last = to !== undefined && end < start ? end + 7 : end;
685
+ for (let at = start;at <= last; at++) {
686
+ days.add(at % 7);
687
+ }
688
+ }
689
+ return [...days].sort((a, b) => a - b);
690
+ }
691
+ WeekDays.of = of;
692
+ function field(days) {
693
+ const sorted = [...new Set(days.map((day) => (day % 7 + 7) % 7))].sort((a, b) => a - b);
694
+ if (sorted.length === 7) {
695
+ return "*";
696
+ }
697
+ return sorted.join(",") === "1,2,3,4,5" ? "1-5" : sorted.join(",");
698
+ }
699
+ WeekDays.field = field;
700
+ })(WeekDays ||= {});
521
701
  var MAX_STEPS = 200000;
522
702
 
523
703
  class CronExpression {
@@ -684,6 +864,8 @@ var EN_DAYS = ["Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fri
684
864
  var ZH_DAYS = ["日", "一", "二", "三", "四", "五", "六"];
685
865
  var ZH_TW_DAYS = ["日", "一", "二", "三", "四", "五", "六"];
686
866
  var JA_DAYS = ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"];
867
+ var EN_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
868
+ var JA_SHORT = ["日", "月", "火", "水", "木", "金", "土"];
687
869
  var WORDS2 = {
688
870
  "en-US": {
689
871
  once: (time) => `Once, ${time}`,
@@ -692,9 +874,13 @@ var WORDS2 = {
692
874
  daily: (time) => `Daily at ${time}`,
693
875
  weekdays: (time) => `Weekdays at ${time}`,
694
876
  weekly: (day, time) => `${EN_DAYS[day]} at ${time}`,
877
+ days: (days, time) => `${days.map((day) => EN_SHORT[day]).join(", ")} at ${time}`,
878
+ weekends: (time) => `Weekends at ${time}`,
695
879
  monthly: (day, time) => `Monthly on day ${day} at ${time}`,
696
880
  hourly: (minute) => minute === 0 ? "Hourly" : `Hourly at :${pad(minute)}`,
697
- cron: (expression) => `Cron ${expression}`
881
+ cron: (expression) => `Cron ${expression}`,
882
+ watch: (path) => `When files change in ${path}`,
883
+ webhook: "When its webhook is called"
698
884
  },
699
885
  "zh-CN": {
700
886
  once: (time) => `${time} 运行一次`,
@@ -703,9 +889,13 @@ var WORDS2 = {
703
889
  daily: (time) => `每天 ${time}`,
704
890
  weekdays: (time) => `工作日 ${time}`,
705
891
  weekly: (day, time) => `每周${ZH_DAYS[day]} ${time}`,
892
+ days: (days, time) => `每周${days.map((day) => ZH_DAYS[day]).join("、")} ${time}`,
893
+ weekends: (time) => `周末 ${time}`,
706
894
  monthly: (day, time) => `每月 ${day} 日 ${time}`,
707
895
  hourly: (minute) => minute === 0 ? "每小时" : `每小时第 ${minute} 分`,
708
- cron: (expression) => `cron ${expression}`
896
+ cron: (expression) => `cron ${expression}`,
897
+ watch: (path) => `${path} 里的文件变化时`,
898
+ webhook: "收到 Webhook 时"
709
899
  },
710
900
  "zh-TW": {
711
901
  once: (time) => `${time} 執行一次`,
@@ -714,9 +904,13 @@ var WORDS2 = {
714
904
  daily: (time) => `每天 ${time}`,
715
905
  weekdays: (time) => `工作日 ${time}`,
716
906
  weekly: (day, time) => `每週${ZH_TW_DAYS[day]} ${time}`,
907
+ days: (days, time) => `每週${days.map((day) => ZH_TW_DAYS[day]).join("、")} ${time}`,
908
+ weekends: (time) => `週末 ${time}`,
717
909
  monthly: (day, time) => `每月 ${day} 日 ${time}`,
718
910
  hourly: (minute) => minute === 0 ? "每小時" : `每小時第 ${minute} 分`,
719
- cron: (expression) => `cron ${expression}`
911
+ cron: (expression) => `cron ${expression}`,
912
+ watch: (path) => `${path} 裡的檔案變化時`,
913
+ webhook: "收到 Webhook 時"
720
914
  },
721
915
  "ja-JP": {
722
916
  once: (time) => `${time}に1回実行`,
@@ -725,9 +919,13 @@ var WORDS2 = {
725
919
  daily: (time) => `毎日 ${time}`,
726
920
  weekdays: (time) => `平日 ${time}`,
727
921
  weekly: (day, time) => `${JA_DAYS[day]} ${time}`,
922
+ days: (days, time) => `毎週${days.map((day) => JA_SHORT[day]).join("・")} ${time}`,
923
+ weekends: (time) => `週末 ${time}`,
728
924
  monthly: (day, time) => `毎月${day}日 ${time}`,
729
925
  hourly: (minute) => minute === 0 ? "毎時間" : `毎時間 :${pad(minute)}`,
730
- cron: (expression) => `Cron ${expression}`
926
+ cron: (expression) => `Cron ${expression}`,
927
+ watch: (path) => `${path} のファイルが変わったとき`,
928
+ webhook: "Webhook を受け取ったとき"
731
929
  }
732
930
  };
733
931
  function pad(value) {
@@ -760,8 +958,17 @@ var ScheduleUtil;
760
958
  const expression = typeof schedule.expression === "string" ? schedule.expression : "";
761
959
  return { kind: "cron", expression: CronExpression.parse(expression).source };
762
960
  }
961
+ case "watch": {
962
+ const path = typeof schedule.path === "string" ? schedule.path.trim() : "";
963
+ if (!path) {
964
+ throw new Error("A task run when files change needs `path`: a folder or a file, of its directory (`.` for all of it) or absolute.");
965
+ }
966
+ return { kind: "watch", path };
967
+ }
968
+ case "webhook":
969
+ return { kind: "webhook" };
763
970
  default:
764
- throw new Error('A schedule is { kind: "once", at }, { kind: "interval", every } or { kind: "cron", expression }.');
971
+ throw new Error('A schedule is { kind: "once", at }, { kind: "interval", every }, { kind: "cron", expression }, { kind: "watch", path } or { kind: "webhook" }.');
765
972
  }
766
973
  }
767
974
  ScheduleUtil.check = check;
@@ -775,6 +982,9 @@ var ScheduleUtil;
775
982
  return new Date(now.getTime() + (Duration.parse(schedule.every) ?? Limits.MIN_INTERVAL_MS));
776
983
  case "cron":
777
984
  return CronExpression.parse(schedule.expression).next(now);
985
+ case "watch":
986
+ case "webhook":
987
+ return;
778
988
  }
779
989
  }
780
990
  ScheduleUtil.next = next;
@@ -782,6 +992,10 @@ var ScheduleUtil;
782
992
  return schedule.kind !== "once";
783
993
  }
784
994
  ScheduleUtil.repeats = repeats;
995
+ function isEvent(schedule) {
996
+ return schedule.kind === "watch" || schedule.kind === "webhook";
997
+ }
998
+ ScheduleUtil.isEvent = isEvent;
785
999
  function notifyLevel(task) {
786
1000
  return task.notify ?? (repeats(task.schedule) ? "error" : "always");
787
1001
  }
@@ -806,6 +1020,10 @@ var ScheduleUtil;
806
1020
  return describeInterval(schedule.every, words);
807
1021
  case "cron":
808
1022
  return describeCron(schedule.expression, words);
1023
+ case "watch":
1024
+ return words.watch(schedule.path);
1025
+ case "webhook":
1026
+ return words.webhook;
809
1027
  }
810
1028
  }
811
1029
  ScheduleUtil.describe = describe;
@@ -836,9 +1054,18 @@ var ScheduleUtil;
836
1054
  if (time && day === "*" && weekday === "1-5") {
837
1055
  return words.weekdays(time);
838
1056
  }
839
- const d = number(weekday);
840
- if (time && day === "*" && d !== undefined && d <= 7) {
841
- return words.weekly(d % 7, time);
1057
+ const days = time && day === "*" ? WeekDays.of(weekday) : undefined;
1058
+ if (time && days?.length === 1) {
1059
+ return words.weekly(days[0], time);
1060
+ }
1061
+ if (time && days?.join(",") === "1,2,3,4,5") {
1062
+ return words.weekdays(time);
1063
+ }
1064
+ if (time && days?.join(",") === "0,6") {
1065
+ return words.weekends(time);
1066
+ }
1067
+ if (time && days && days.length > 1) {
1068
+ return words.days(days, time);
842
1069
  }
843
1070
  const date = number(day);
844
1071
  if (time && date !== undefined && weekday === "*") {
@@ -860,6 +1087,279 @@ var ScheduleUtil;
860
1087
  }
861
1088
  })(ScheduleUtil ||= {});
862
1089
 
1090
+ // ../ta-protocol/esm/common/message-protocol.js
1091
+ var TaMessageContext;
1092
+ (function(TaMessageContext2) {
1093
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
1094
+ function wrap(context, message) {
1095
+ return `<context>
1096
+ ${context}
1097
+ </context>
1098
+ ${message}`;
1099
+ }
1100
+ TaMessageContext2.wrap = wrap;
1101
+ function strip(message) {
1102
+ return message.replace(BLOCK, "");
1103
+ }
1104
+ TaMessageContext2.strip = strip;
1105
+ function read(message) {
1106
+ var _a;
1107
+ const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
1108
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
1109
+ }
1110
+ TaMessageContext2.read = read;
1111
+ })(TaMessageContext || (TaMessageContext = {}));
1112
+ var TaMessageSource;
1113
+ (function(TaMessageSource2) {
1114
+ TaMessageSource2.DOUBLE = "ta:double";
1115
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
1116
+ function mark(message, from, detail) {
1117
+ return marked(message, line(from, detail));
1118
+ }
1119
+ TaMessageSource2.mark = mark;
1120
+ function notice(message, from, detail) {
1121
+ return marked(message, line(from, detail, true));
1122
+ }
1123
+ TaMessageSource2.notice = notice;
1124
+ function line(from, detail, notice2 = false) {
1125
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
1126
+ }
1127
+ TaMessageSource2.line = line;
1128
+ function of(message) {
1129
+ const context = TaMessageContext.read(message);
1130
+ const match = context === undefined ? null : LINE.exec(context);
1131
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
1132
+ }
1133
+ TaMessageSource2.of = of;
1134
+ function isNotice(message) {
1135
+ var _a;
1136
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
1137
+ }
1138
+ TaMessageSource2.isNotice = isNotice;
1139
+ TaMessageSource2.SECTION = "ta-sources";
1140
+ TaMessageSource2.PROMPT = [
1141
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
1142
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
1143
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
1144
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
1145
+ "- Never quote it as the user's words nor answer it as if they had said it."
1146
+ ].join(`
1147
+ `);
1148
+ function marked(message, source) {
1149
+ if (/^[/!]/.test(message) || of(message)) {
1150
+ return message;
1151
+ }
1152
+ const context = TaMessageContext.read(message);
1153
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
1154
+ ${source}`, TaMessageContext.strip(message));
1155
+ }
1156
+ })(TaMessageSource || (TaMessageSource = {}));
1157
+ var TaImageNote;
1158
+ (function(TaImageNote2) {
1159
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
1160
+ function strip(text) {
1161
+ const lines = text.split(`
1162
+ `);
1163
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
1164
+ if (kept.length === lines.length) {
1165
+ return text;
1166
+ }
1167
+ return kept.join(`
1168
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
1169
+ }
1170
+ TaImageNote2.strip = strip;
1171
+ })(TaImageNote || (TaImageNote = {}));
1172
+ var TaImageSize;
1173
+ (function(TaImageSize2) {
1174
+ const JPEG_BYTES = 256 * 1024;
1175
+ function of(base64) {
1176
+ var _a, _b, _c;
1177
+ let bytes;
1178
+ try {
1179
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
1180
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
1181
+ } catch (_d) {
1182
+ return;
1183
+ }
1184
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
1185
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
1186
+ }
1187
+ TaImageSize2.of = of;
1188
+ function u16be(bytes, at) {
1189
+ return bytes[at] << 8 | bytes[at + 1];
1190
+ }
1191
+ function u16le(bytes, at) {
1192
+ return bytes[at] | bytes[at + 1] << 8;
1193
+ }
1194
+ function u24le(bytes, at) {
1195
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
1196
+ }
1197
+ function u32be(bytes, at) {
1198
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
1199
+ }
1200
+ function text(bytes, at, length) {
1201
+ return String.fromCharCode(...bytes.subarray(at, at + length));
1202
+ }
1203
+ function png(bytes) {
1204
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
1205
+ }
1206
+ function gif(bytes) {
1207
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
1208
+ }
1209
+ function webp(bytes) {
1210
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
1211
+ return;
1212
+ }
1213
+ switch (text(bytes, 12, 4)) {
1214
+ case "VP8 ":
1215
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
1216
+ case "VP8L": {
1217
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
1218
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
1219
+ }
1220
+ case "VP8X":
1221
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
1222
+ default:
1223
+ return;
1224
+ }
1225
+ }
1226
+ function jpeg(bytes) {
1227
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
1228
+ return;
1229
+ }
1230
+ let at = 2;
1231
+ while (at + 9 < bytes.length) {
1232
+ if (bytes[at] !== 255) {
1233
+ return;
1234
+ }
1235
+ const marker = bytes[at + 1];
1236
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
1237
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
1238
+ }
1239
+ at += 2 + u16be(bytes, at + 2);
1240
+ }
1241
+ return;
1242
+ }
1243
+ })(TaImageSize || (TaImageSize = {}));
1244
+ var TaAgentSummary;
1245
+ (function(TaAgentSummary2) {
1246
+ const START = /^\s*<conversation_history_summary>/;
1247
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
1248
+ function read(text) {
1249
+ if (!START.test(text)) {
1250
+ return;
1251
+ }
1252
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
1253
+ }
1254
+ TaAgentSummary2.read = read;
1255
+ function strip(text) {
1256
+ return text.replace(BLOCK, "");
1257
+ }
1258
+ TaAgentSummary2.strip = strip;
1259
+ })(TaAgentSummary || (TaAgentSummary = {}));
1260
+ var TaSkillUse;
1261
+ (function(TaSkillUse2) {
1262
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
1263
+ function parse(message) {
1264
+ var _a;
1265
+ const match = BLOCK.exec(message);
1266
+ if (!match) {
1267
+ return;
1268
+ }
1269
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
1270
+ }
1271
+ TaSkillUse2.parse = parse;
1272
+ function command(use) {
1273
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
1274
+ }
1275
+ TaSkillUse2.command = command;
1276
+ })(TaSkillUse || (TaSkillUse = {}));
1277
+ var TaTaskNote;
1278
+ (function(TaTaskNote2) {
1279
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
1280
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
1281
+ function write(note) {
1282
+ const attributes = [`id="${quote(note.id)}"`];
1283
+ if (note.was !== undefined) {
1284
+ attributes.push(`was="${quote(note.was)}"`);
1285
+ }
1286
+ attributes.push(`title="${quote(note.title)}"`);
1287
+ if (note.status !== undefined) {
1288
+ attributes.push(`status="${quote(note.status)}"`);
1289
+ }
1290
+ return `<task_${note.kind} ${attributes.join(" ")}>
1291
+ ${note.body}
1292
+ </task_${note.kind}>`;
1293
+ }
1294
+ TaTaskNote2.write = write;
1295
+ function parse(text) {
1296
+ const match = NOTE.exec(text.trim());
1297
+ if (!match) {
1298
+ return;
1299
+ }
1300
+ const attributes = {};
1301
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
1302
+ attributes[name] = unquote(value);
1303
+ }
1304
+ if (!attributes.id || attributes.title === undefined) {
1305
+ return;
1306
+ }
1307
+ const { id, title, status, was } = attributes;
1308
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
1309
+ }
1310
+ TaTaskNote2.parse = parse;
1311
+ function quote(text) {
1312
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
1313
+ }
1314
+ function unquote(text) {
1315
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
1316
+ }
1317
+ })(TaTaskNote || (TaTaskNote = {}));
1318
+ var TaSecretRef;
1319
+ (function(TaSecretRef2) {
1320
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
1321
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
1322
+ const KINDS = [
1323
+ [/^PHONE(?:_\d+)?$/, "phone"],
1324
+ [/^EMAIL(?:_\d+)?$/, "email"],
1325
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
1326
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
1327
+ ];
1328
+ function has(text) {
1329
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
1330
+ }
1331
+ TaSecretRef2.has = has;
1332
+ function kind(name) {
1333
+ var _a;
1334
+ var _b;
1335
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
1336
+ }
1337
+ TaSecretRef2.kind = kind;
1338
+ function split(text) {
1339
+ if (!has(text)) {
1340
+ return [{ text }];
1341
+ }
1342
+ const parts = [];
1343
+ let at = 0;
1344
+ for (const match of text.matchAll(REF)) {
1345
+ if (match.index > at) {
1346
+ parts.push({ text: text.slice(at, match.index) });
1347
+ }
1348
+ parts.push({ secret: match[1], kind: kind(match[1]) });
1349
+ at = match.index + match[0].length;
1350
+ }
1351
+ if (at < text.length) {
1352
+ parts.push({ text: text.slice(at) });
1353
+ }
1354
+ return parts;
1355
+ }
1356
+ TaSecretRef2.split = split;
1357
+ function plain(text, label) {
1358
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
1359
+ }
1360
+ TaSecretRef2.plain = plain;
1361
+ })(TaSecretRef || (TaSecretRef = {}));
1362
+
863
1363
  // web-src/task-extension.ts
864
1364
  var PROMPT_MAX = 4000;
865
1365
  var ANSWER_MAX = 2000;
@@ -867,10 +1367,7 @@ var TaskExtension;
867
1367
  ((TaskExtension) => {
868
1368
  function message(task, runs, language) {
869
1369
  const words = CronWords.of(language);
870
- return `<context>
871
- ${context(task, runs)}
872
- </context>
873
- ${CronWords.format(words.extensionAsk, { name: task.name })}`;
1370
+ return TaMessageContext.wrap(context(task, runs), CronWords.format(words.extensionAsk, { name: task.name }));
874
1371
  }
875
1372
  TaskExtension.message = message;
876
1373
  function context(task, runs) {
@@ -915,10 +1412,7 @@ var TaskChange;
915
1412
  ((TaskChange) => {
916
1413
  function message(task, runs, request, language) {
917
1414
  const words = CronWords.of(language);
918
- return `<context>
919
- ${context(task, runs)}
920
- </context>
921
- ${CronWords.format(words.changeAsk, { name: task.name, text: request.trim() })}`;
1415
+ return TaMessageContext.wrap(context(task, runs), CronWords.format(words.changeAsk, { name: task.name, text: request.trim() }));
922
1416
  }
923
1417
  TaskChange.message = message;
924
1418
  function context(task, runs) {
@@ -962,8 +1456,15 @@ function message(error) {
962
1456
  }
963
1457
  function until(time, now = Date.now()) {
964
1458
  const minutes = Math.max(1, Math.round((time - now) / 60000));
965
- const language = pi.ui.language;
966
1459
  const [amount, unit] = minutes < 60 ? [minutes, "minute"] : minutes < 48 * 60 ? [Math.round(minutes / 60), "hour"] : [Math.round(minutes / 1440), "day"];
1460
+ return amountOf(amount, unit);
1461
+ }
1462
+ function length(duration) {
1463
+ const minutes = Math.round((Duration.parse(duration) ?? 0) / 60000);
1464
+ return minutes >= 60 && minutes % 60 === 0 ? amountOf(minutes / 60, "hour") : amountOf(minutes, "minute");
1465
+ }
1466
+ function amountOf(amount, unit) {
1467
+ const language = pi.ui.language;
967
1468
  const unitMap = {
968
1469
  "zh-CN": { minute: "分钟", hour: "小时", day: "天" },
969
1470
  "zh-TW": { minute: "分鐘", hour: "小時", day: "天" },
@@ -1186,6 +1687,7 @@ function nextTasks(tasks, shown = SHOWN) {
1186
1687
  return tasks.filter((task) => task.lastStatus === "running" || task.enabled && task.nextRunAt).sort((a, b) => at(a) - at(b)).slice(0, shown);
1187
1688
  }
1188
1689
  function NextCard({ client }) {
1690
+ const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
1189
1691
  const { tasks, loaded } = React.useSyncExternalStore((listener) => client.subscribe(listener), () => client.state);
1190
1692
  const [now, setNow] = React.useState(Date.now());
1191
1693
  React.useEffect(() => {
@@ -1193,8 +1695,8 @@ function NextCard({ client }) {
1193
1695
  return () => clearInterval(timer);
1194
1696
  }, []);
1195
1697
  if (!loaded) {
1196
- return /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
1197
- rows: 2
1698
+ return /* @__PURE__ */ React.createElement(Loading, {
1699
+ compact: true
1198
1700
  });
1199
1701
  }
1200
1702
  const next = nextTasks(tasks);
@@ -1260,13 +1762,212 @@ function watchRuns() {
1260
1762
  });
1261
1763
  }
1262
1764
 
1765
+ // web-src/when.ts
1766
+ var WHEN_FORMS = "every 30m (or 30m, 2h, 1d), daily 09:00, weekdays 18:00, weekends 10:00, mon 09:00, mon,wed,fri 09:00, tue-thu 09:00, @daily, @hourly, cron 0 9 * * 1-5 (or the five fields alone), in 45m, at 15:30, at 2026-12-01 08:15, watch src (when files change under a path of its directory, . for all of it), webhook";
1767
+ var DAYS = new RegExp(`^(?:${WeekDays.NAMES.join("|")})(?:[-,](?:${WeekDays.NAMES.join("|")}))*$`, "i");
1768
+ var HM = /^(\d{1,2}):(\d{2})$/;
1769
+ var CRON_WORD = /^[\d*,/a-z-]+$/i;
1770
+ function pad2(value) {
1771
+ return String(value).padStart(2, "0");
1772
+ }
1773
+ var When;
1774
+ ((When) => {
1775
+ function parse(text, now) {
1776
+ const { schedule, rest } = leading(text, now);
1777
+ if (rest.trim()) {
1778
+ throw new Error(`${JSON.stringify(text)} says more than when: ${JSON.stringify(rest.trim())}. when is one of: ${WHEN_FORMS}.`);
1779
+ }
1780
+ return schedule;
1781
+ }
1782
+ When.parse = parse;
1783
+ function leading(text, now) {
1784
+ const source = text.trim();
1785
+ const quote = source[0];
1786
+ if (quote === '"' || quote === "'") {
1787
+ const end = source.indexOf(quote, 1);
1788
+ if (end < 0) {
1789
+ throw new Error("The cron expression has no closing quote.");
1790
+ }
1791
+ return { schedule: ScheduleUtil.check({ kind: "cron", expression: source.slice(1, end) }), rest: source.slice(end + 1) };
1792
+ }
1793
+ const words = Words.of(source);
1794
+ const word = (index) => words.word(index);
1795
+ const first = word(0).toLowerCase();
1796
+ const done = (schedule, used) => ({ schedule: ScheduleUtil.check(schedule), rest: words.after(used) });
1797
+ if (first === "every" && Duration.parse(word(1)) !== undefined) {
1798
+ return done({ kind: "interval", every: word(1) }, 2);
1799
+ }
1800
+ if (Duration.parse(first) !== undefined) {
1801
+ return done({ kind: "interval", every: first }, 1);
1802
+ }
1803
+ if (first.startsWith("@")) {
1804
+ return done({ kind: "cron", expression: first }, 1);
1805
+ }
1806
+ if (first === "hourly") {
1807
+ return done({ kind: "cron", expression: "0 * * * *" }, 1);
1808
+ }
1809
+ if (first === "cron") {
1810
+ const nickname = word(1).startsWith("@") || word(1).startsWith('"') || word(1).startsWith("'");
1811
+ if (nickname) {
1812
+ const inner = leading(words.after(1), now);
1813
+ return { schedule: inner.schedule, rest: inner.rest };
1814
+ }
1815
+ return done({ kind: "cron", expression: words.slice(1, 6).join(" ") }, 6);
1816
+ }
1817
+ const days = first === "daily" ? "*" : first === "weekdays" ? "1-5" : first === "weekends" ? "0,6" : DAYS.test(first) ? first : undefined;
1818
+ if (days !== undefined) {
1819
+ const time = HM.exec(word(1));
1820
+ if (!time || Number(time[1]) > 23 || Number(time[2]) > 59) {
1821
+ throw new Error(`${first} needs a time after it, as ${first} 09:00.`);
1822
+ }
1823
+ const field = WeekDays.field(WeekDays.of(days) ?? []);
1824
+ return done({ kind: "cron", expression: `${Number(time[2])} ${Number(time[1])} * * ${field}` }, 2);
1825
+ }
1826
+ if (first === "in") {
1827
+ const ms = Duration.parse(word(1));
1828
+ if (ms === undefined) {
1829
+ throw new Error("in needs a duration after it, as in 45m.");
1830
+ }
1831
+ return done({ kind: "once", at: new Date(now.getTime() + ms).toISOString() }, 2);
1832
+ }
1833
+ if (first === "at") {
1834
+ const at = clockTime([word(1), word(2)], now);
1835
+ if (!at) {
1836
+ throw new Error("at needs a time after it: at 15:30 (today, or tomorrow once it passed), at 2026-12-01 08:15.");
1837
+ }
1838
+ return done({ kind: "once", at: at.date.toISOString() }, 1 + at.words);
1839
+ }
1840
+ if (first === "watch") {
1841
+ return done({ kind: "watch", path: word(1) || "." }, word(1) ? 2 : 1);
1842
+ }
1843
+ if (first === "webhook") {
1844
+ return done({ kind: "webhook" }, 1);
1845
+ }
1846
+ const five = words.slice(0, 5);
1847
+ if (five.length === 5 && five.every((part) => CRON_WORD.test(part))) {
1848
+ try {
1849
+ return done({ kind: "cron", expression: five.join(" ") }, 5);
1850
+ } catch {}
1851
+ }
1852
+ throw new Error(`Start with when: ${JSON.stringify(word(0))} is none of: ${WHEN_FORMS}.`);
1853
+ }
1854
+ When.leading = leading;
1855
+ function clockTime(words, now) {
1856
+ const [first = "", second = ""] = words;
1857
+ const day = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
1858
+ const time = HM.exec(first);
1859
+ if (time) {
1860
+ const date2 = new Date(now.getTime());
1861
+ date2.setHours(Number(time[1]), Number(time[2]), 0, 0);
1862
+ if (date2.getTime() <= now.getTime()) {
1863
+ date2.setDate(date2.getDate() + 1);
1864
+ }
1865
+ return valid(date2, Number(time[1]) < 24 && Number(time[2]) < 60) ? { date: date2, words: 1 } : undefined;
1866
+ }
1867
+ const date = day.exec(first);
1868
+ const later = HM.exec(second);
1869
+ if (date) {
1870
+ const at = new Date(Number(date[1]), Number(date[2]) - 1, Number(date[3]), later ? Number(later[1]) : 9, later ? Number(later[2]) : 0);
1871
+ return valid(at, true) ? { date: at, words: later ? 2 : 1 } : undefined;
1872
+ }
1873
+ const iso = /^\d{4}-\d{2}-\d{2}T/.test(first) ? new Date(first) : undefined;
1874
+ return iso && valid(iso, true) ? { date: iso, words: 1 } : undefined;
1875
+ }
1876
+ When.clockTime = clockTime;
1877
+ function format(schedule) {
1878
+ switch (schedule.kind) {
1879
+ case "interval":
1880
+ return `every ${schedule.every}`;
1881
+ case "once": {
1882
+ const at = new Date(schedule.at);
1883
+ return `at ${at.getFullYear()}-${pad2(at.getMonth() + 1)}-${pad2(at.getDate())} ${pad2(at.getHours())}:${pad2(at.getMinutes())}`;
1884
+ }
1885
+ case "watch":
1886
+ return `watch ${schedule.path}`;
1887
+ case "webhook":
1888
+ return "webhook";
1889
+ case "cron": {
1890
+ const daily = timeAndDays(schedule.expression);
1891
+ if (!daily) {
1892
+ return `cron ${schedule.expression}`;
1893
+ }
1894
+ const field = WeekDays.field(daily.days);
1895
+ const days = field === "*" ? "daily" : field === "1-5" ? "weekdays" : field === "0,6" ? "weekends" : daily.days.map((day) => WeekDays.NAMES[day]).join(",");
1896
+ return `${days} ${daily.time}`;
1897
+ }
1898
+ }
1899
+ }
1900
+ When.format = format;
1901
+ function timeAndDays(expression) {
1902
+ const [minute, hour, day, month, weekday] = (NICKNAMES[expression.toLowerCase()] ?? expression).split(" ");
1903
+ if (!/^\d+$/.test(minute ?? "") || !/^\d+$/.test(hour ?? "") || day !== "*" || month !== "*") {
1904
+ return;
1905
+ }
1906
+ const days = WeekDays.of(weekday ?? "");
1907
+ return days && { time: `${pad2(Number(hour))}:${pad2(Number(minute))}`, hour: Number(hour), minute: Number(minute), days };
1908
+ }
1909
+ When.timeAndDays = timeAndDays;
1910
+ function nextTimes(schedule, now, count = 3) {
1911
+ const times = [];
1912
+ for (let next = ScheduleUtil.next(schedule, now);next && times.length < count; next = ScheduleUtil.next(schedule, next)) {
1913
+ times.push(next);
1914
+ if (schedule.kind === "once") {
1915
+ break;
1916
+ }
1917
+ }
1918
+ return times;
1919
+ }
1920
+ When.nextTimes = nextTimes;
1921
+ function preview(rule, now, count = 3) {
1922
+ const schedule = typeof rule === "string" ? parse(rule, now) : ScheduleUtil.check(rule);
1923
+ const next = nextTimes(schedule, now, Math.min(10, Math.max(1, count)));
1924
+ if (next.length === 0 && !ScheduleUtil.isEvent(schedule)) {
1925
+ throw new Error(schedule.kind === "once" ? "That time has passed: give one to come." : "That rule never comes round: check the cron expression.");
1926
+ }
1927
+ return { schedule, when: format(schedule), describe: ScheduleUtil.describe(schedule, "en-US", now), next: next.map((time) => time.toISOString()) };
1928
+ }
1929
+ When.preview = preview;
1930
+ function valid(date, ok) {
1931
+ return ok && !Number.isNaN(date.getTime());
1932
+ }
1933
+ })(When ||= {});
1934
+
1935
+ class Words {
1936
+ source;
1937
+ list;
1938
+ constructor(source, list) {
1939
+ this.source = source;
1940
+ this.list = list;
1941
+ }
1942
+ static of(source) {
1943
+ const list = [];
1944
+ for (const match of source.matchAll(/\S+/g)) {
1945
+ list.push({ text: match[0], end: (match.index ?? 0) + match[0].length });
1946
+ }
1947
+ return new Words(source, list);
1948
+ }
1949
+ word(index) {
1950
+ return this.list[index]?.text ?? "";
1951
+ }
1952
+ slice(start, end) {
1953
+ return this.list.slice(start, end).map((word) => word.text);
1954
+ }
1955
+ after(count) {
1956
+ if (count <= 0) {
1957
+ return this.source;
1958
+ }
1959
+ const last = this.list[Math.min(count, this.list.length) - 1];
1960
+ return last ? this.source.slice(last.end) : "";
1961
+ }
1962
+ }
1963
+
1263
1964
  // web-src/commands.ts
1264
1965
  var FLAG_NAMES = ["name", "notify", "model", "thinking", "cwd", "timeout"];
1265
1966
  var TRAILING_FLAG = new RegExp(`(?:^|\\s)--(${FLAG_NAMES.join("|")})(?:=|\\s+)("[^"]*"|'[^']*'|\\S*)\\s*$`);
1266
1967
  var ACTIONS = ["add", "list", "show", "runs", "run", "enable", "disable", "set", "remove", "clear", "help"];
1267
1968
  var HELP = `Scheduled tasks: each run is a conversation of its own in the Ta service, which runs them while it runs.
1268
1969
 
1269
- /loop <when> <prompt> repeat: 30m, 2h, @daily, @hourly, or a cron expression in quotes ("0 9 * * 1-5")
1970
+ /loop <when> <prompt> repeat: 30m, daily 09:00, weekdays 18:00, mon,thu 09:00, @hourly, or cron 0 9 * * 1-5
1270
1971
  /remind in <duration> <prompt> once, after a while: in 45m
1271
1972
  /remind at <time> <prompt> once, at a time: at 15:30, at 2026-11-12 09:00
1272
1973
  /schedule add <when> <prompt> as /loop
@@ -1364,53 +2065,15 @@ var CommandParser;
1364
2065
  return { ref: rest, patch: patch2 };
1365
2066
  }
1366
2067
  CommandParser.patch = patch;
1367
- function leadingSchedule(text) {
1368
- const trimmed = text.trim();
1369
- const quote = trimmed[0];
1370
- if (quote === '"' || quote === "'") {
1371
- const end = trimmed.indexOf(quote, 1);
1372
- if (end < 0) {
1373
- throw new Error("The cron expression has no closing quote.");
1374
- }
1375
- return { schedule: ScheduleUtil.check({ kind: "cron", expression: trimmed.slice(1, end) }), remainder: trimmed.slice(end + 1) };
1376
- }
1377
- const [first = ""] = trimmed.split(/\s+/, 1);
1378
- const remainder = trimmed.slice(first.length);
1379
- if (first.startsWith("@")) {
1380
- return { schedule: ScheduleUtil.check({ kind: "cron", expression: first }), remainder };
1381
- }
1382
- if (Duration.parse(first) !== undefined) {
1383
- return { schedule: ScheduleUtil.check({ kind: "interval", every: first }), remainder };
1384
- }
1385
- throw new Error('Start with when: 30m, 2h, @daily, or a cron expression in quotes such as "0 9 * * 1-5".');
2068
+ function leadingSchedule(text, now = new Date) {
2069
+ const { schedule, rest } = When.leading(text, now);
2070
+ return { schedule, remainder: rest };
1386
2071
  }
1387
2072
  CommandParser.leadingSchedule = leadingSchedule;
1388
2073
  function clockTime(words, now) {
1389
- const [first = "", second = ""] = words;
1390
- const hm = /^(\d{1,2}):(\d{2})$/;
1391
- const day = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
1392
- const time = hm.exec(first);
1393
- if (time) {
1394
- const date2 = new Date(now.getTime());
1395
- date2.setHours(Number(time[1]), Number(time[2]), 0, 0);
1396
- if (date2.getTime() <= now.getTime()) {
1397
- date2.setDate(date2.getDate() + 1);
1398
- }
1399
- return valid(date2, Number(time[1]) < 24 && Number(time[2]) < 60) ? { date: date2, words: 1 } : undefined;
1400
- }
1401
- const date = day.exec(first);
1402
- const later = hm.exec(second);
1403
- if (date) {
1404
- const at = new Date(Number(date[1]), Number(date[2]) - 1, Number(date[3]), later ? Number(later[1]) : 9, later ? Number(later[2]) : 0);
1405
- return valid(at, true) ? { date: at, words: later ? 2 : 1 } : undefined;
1406
- }
1407
- const iso = /^\d{4}-\d{2}-\d{2}T/.test(first) ? new Date(first) : undefined;
1408
- return iso && valid(iso, true) ? { date: iso, words: 1 } : undefined;
2074
+ return When.clockTime(words, now);
1409
2075
  }
1410
2076
  CommandParser.clockTime = clockTime;
1411
- function valid(date, ok) {
1412
- return ok && !Number.isNaN(date.getTime());
1413
- }
1414
2077
  function input(schedule, prompt, flags) {
1415
2078
  const text = prompt.trim();
1416
2079
  if (!text) {
@@ -1453,19 +2116,34 @@ var CommandParser;
1453
2116
  var CronText;
1454
2117
  ((CronText) => {
1455
2118
  function task(task2, now = new Date) {
1456
- const state = !task2.enabled ? "off" : task2.lastStatus === "running" ? "running" : task2.nextRunAt ? `next ${ScheduleUtil.clock(new Date(task2.nextRunAt), now)}` : "done";
2119
+ const state = !task2.enabled ? "off" : task2.lastStatus === "running" ? "running" : task2.nextRunAt ? `next ${ScheduleUtil.clock(new Date(task2.nextRunAt), now)}` : ScheduleUtil.isEvent(task2.schedule) ? "waiting for its event" : "done";
1457
2120
  const last = task2.lastStatus && task2.lastStatus !== "running" ? `, last ${task2.lastStatus}` : "";
1458
2121
  const timeout = task2.timeout ? `, stops after ${task2.timeout}` : "";
1459
- return `${task2.id} ${task2.name} (${ScheduleUtil.describe(task2.schedule, "en", now)}; ${state}${last}${timeout}) in ${task2.cwd}`;
2122
+ return `${task2.id} ${task2.name} (when: ${When.format(task2.schedule)}; ${state}${last}${timeout}) in ${task2.cwd}`;
1460
2123
  }
1461
2124
  CronText.task = task;
2125
+ function nextTimes(task2, now = new Date) {
2126
+ if (!task2.enabled || !task2.nextRunAt) {
2127
+ return "";
2128
+ }
2129
+ const times = When.nextTimes(task2.schedule, new Date(Math.max(now.getTime(), new Date(task2.nextRunAt).getTime() - 1)), 3);
2130
+ return `
2131
+ next: ${times.map((time) => ScheduleUtil.clock(time, now)).join(", ")}`;
2132
+ }
2133
+ CronText.nextTimes = nextTimes;
2134
+ function preview(preview2, now = new Date) {
2135
+ const next = preview2.next.length ? preview2.next.map((time) => ScheduleUtil.clock(new Date(time), now)).join(", ") : "when its event comes";
2136
+ return `when: ${preview2.when} (${preview2.describe})
2137
+ next: ${next}`;
2138
+ }
2139
+ CronText.preview = preview;
1462
2140
  function run(run2, now = new Date) {
1463
2141
  const time = ScheduleUtil.clock(new Date(run2.startedAt), now);
1464
2142
  const took = run2.endedAt ? ` in ${Duration.format(new Date(run2.endedAt).getTime() - new Date(run2.startedAt).getTime())}` : "";
1465
2143
  const what = run2.error ?? run2.summary ?? "";
1466
2144
  const file = run2.sessionFile ? `
1467
2145
  conversation: ${run2.sessionFile}` : "";
1468
- return `${run2.id} ${time} ${run2.status}${took}${run2.trigger === "manual" ? " (by hand)" : ""}${what ? `
2146
+ return `${run2.id} ${time} ${run2.status}${took}${run2.trigger === "manual" ? " (by hand)" : run2.trigger === "event" ? " (by its event)" : ""}${what ? `
1469
2147
  ${what.replace(/\n/g, `
1470
2148
  `)}` : ""}${file}`;
1471
2149
  }
@@ -1587,9 +2265,18 @@ var STYLE = `
1587
2265
 
1588
2266
  /* The page: it scrolls in its own box, which takes what the main area has left under its head. */
1589
2267
  .tcr-scroll { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
1590
- .tcr-page { box-sizing: border-box; width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 24px 64px; }
1591
- .tcr-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; min-height: 28px; }
1592
- .tcr-stat { color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); }
2268
+ .tcr-page { box-sizing: border-box; width: 100%; max-width: var(--ta-page-wide); margin: 0 auto; padding: 20px 24px 64px; }
2269
+ /* What the page lists: the segmented control of the pages (.ta-segmented), at its own width, each with its count. */
2270
+ .tcr-filters { display: inline-grid; margin-bottom: 16px; max-width: 100%; }
2271
+ .tcr-filters button { padding: 0 14px; font: inherit; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; }
2272
+ .tcr-filter-count { color: var(--ta-muted); font-weight: 400; font-variant-numeric: tabular-nums; }
2273
+ .tcr-filter-failed .tcr-filter-count { color: var(--ta-red); }
2274
+ /* The tasks that are on, by when they run next: a quiet title over each group. */
2275
+ .tcr-group + .tcr-group { margin-top: 20px; }
2276
+ .tcr-group-title { display: flex; align-items: center; gap: 6px; margin: 0 2px 8px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 600; }
2277
+ .tcr-group-count { font-weight: 400; font-variant-numeric: tabular-nums; }
2278
+ .tcr-none { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 40px 0; color: var(--ta-muted); font-size: calc(13.5px * var(--ta-font-scale)); }
2279
+ .tcr-none > svg { color: var(--ta-green); }
1593
2280
  /* The head: the title in the middle, the + at the right, a box of the same width on the left to keep it there. */
1594
2281
  .tcr-title-bar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; padding-left: 36px; }
1595
2282
 
@@ -1603,10 +2290,6 @@ var STYLE = `
1603
2290
  .tcr-button > svg { flex: none; color: var(--ta-secondary); }
1604
2291
  .tcr-primary { background: var(--ta-brand); border-color: var(--ta-brand); color: var(--ta-brand-text); }
1605
2292
  .tcr-primary:hover:not(:disabled) { background: var(--ta-brand); opacity: .88; }
1606
- /* What hands the task to Ta to make more of: green, as what Ta makes. */
1607
- .tcr-accent { border-color: color-mix(in srgb, var(--ta-green) 45%, var(--ta-border)); background: color-mix(in srgb, var(--ta-green) 9%, var(--ta-card)); }
1608
- .tcr-accent > svg { color: var(--ta-green); }
1609
- .tcr-accent:hover:not(:disabled) { background: color-mix(in srgb, var(--ta-green) 16%, var(--ta-card)); }
1610
2293
  .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; }
1611
2294
  .tcr-link:hover { text-decoration: underline; }
1612
2295
  .tcr-icon { position: relative; 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; transition: background 120ms, color 120ms; }
@@ -1619,12 +2302,6 @@ var STYLE = `
1619
2302
 
1620
2303
  /* The tasks */
1621
2304
  .tcr-list { display: flex; flex-direction: column; gap: 10px; }
1622
- /* The tasks that are off, folded under the list: a quiet title that opens them. */
1623
- .tcr-off-group { margin-top: 18px; }
1624
- .tcr-fold { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 10px -4px; padding: 4px 8px 4px 4px; border: 0; border-radius: 8px; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 500; cursor: pointer; }
1625
- .tcr-fold:hover { background: var(--ta-hover); color: var(--ta-text); }
1626
- .tcr-fold .tcr-count { margin-left: 2px; }
1627
- .tcr-off-group.tcr-open .tcr-fold .tcr-chevron { transform: rotate(90deg); }
1628
2305
  .tcr-task { border: 1px solid var(--ta-border-muted); border-radius: 14px; background: var(--ta-card); transition: border-color 140ms, box-shadow 180ms; animation: tcr-in 160ms var(--ta-ease) both; }
1629
2306
  .tcr-task:hover, .tcr-task.tcr-open { border-color: var(--ta-border); }
1630
2307
  .tcr-task.tcr-open { box-shadow: var(--ta-shadow-pop); }
@@ -1633,19 +2310,21 @@ var STYLE = `
1633
2310
  /* What opens the task: the mark of its state, its name over its rule, directory and last run, then its next run. */
1634
2311
  .tcr-task-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; min-height: 64px; padding: 10px 6px 10px 14px; border: 0; border-radius: 14px 0 0 14px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; outline: none; }
1635
2312
  .tcr-task-main:focus-visible { box-shadow: inset 0 0 0 2px var(--ta-border-focus); }
1636
- /* A tile of the color of the task's state, its last run a dot at its corner. */
2313
+ /* A tile of the color of how the task's last run went. */
1637
2314
  .tcr-mark { position: relative; flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--ta-chip); color: var(--ta-secondary); }
1638
- .tcr-mark .tcr-dot { position: absolute; right: -2px; bottom: -2px; box-shadow: 0 0 0 2.5px var(--ta-card); }
1639
2315
  .tcr-tone-success { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
1640
2316
  .tcr-tone-error, .tcr-tone-missed { background: color-mix(in srgb, var(--ta-red) 13%, transparent); color: var(--ta-red); }
1641
2317
  .tcr-tone-running { background: color-mix(in srgb, var(--ta-blue) 15%, transparent); color: var(--ta-blue); }
1642
2318
  .tcr-task-text { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
1643
2319
  .tcr-task-meta { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1644
2320
  .tcr-task-name { min-width: 0; overflow: hidden; font-size: calc(14.5px * var(--ta-font-scale)); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
2321
+ .tcr-task-rule { flex: none; white-space: nowrap; color: var(--ta-secondary); }
2322
+ .tcr-task-meta > * + *::before { content: '·'; margin-right: 8px; color: var(--ta-muted); }
1645
2323
  .tcr-task-dir { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1646
2324
  .tcr-task-last { flex: none; white-space: nowrap; }
1647
2325
  .tcr-task-next { display: none; flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
1648
- .tcr-task-last::before { content: '·'; margin-right: 8px; }
2326
+ .tcr-task-last.tcr-is-error { color: var(--ta-red); }
2327
+ .tcr-last-short { display: none; }
1649
2328
  .tcr-task-state { flex: none; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1650
2329
  .tcr-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ta-border); }
1651
2330
  .tcr-success { background: var(--ta-green); }
@@ -1665,6 +2344,10 @@ var STYLE = `
1665
2344
  .tcr-detail { display: flex; flex-direction: column; margin: 0 16px; padding: 14px 0 16px; border-top: 1px solid var(--ta-border-muted); animation: tcr-in 160ms var(--ta-ease); }
1666
2345
  .tcr-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
1667
2346
  .tcr-stats { margin-left: auto; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
2347
+ /* How a task is set, in a line of facts under its buttons. */
2348
+ .tcr-facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: -4px 0 16px; color: var(--ta-text); font-size: calc(12.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
2349
+ .tcr-fact { display: inline-flex; gap: 6px; min-width: 0; white-space: nowrap; }
2350
+ .tcr-fact-label { color: var(--ta-muted); }
1668
2351
  .tcr-label { display: flex; align-items: center; margin: 0 0 8px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; }
1669
2352
  .tcr-prompt-block { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
1670
2353
  .tcr-prompt-text { padding: 10px 12px; border-radius: 10px; background: var(--ta-chip); color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
@@ -1726,6 +2409,23 @@ var STYLE = `
1726
2409
  /* As the segmented controls of the page (its settings). */
1727
2410
  .tcr-segment[aria-pressed='true'] { background: var(--ta-segment, var(--ta-card)); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--ta-border); }
1728
2411
  .tcr-preview { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--ta-green) 11%, transparent); color: var(--ta-green); font-size: calc(12.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
2412
+ /* The days of a rule at times: a button a day, Monday first, and every day and the weekdays a tap away. */
2413
+ .tcr-days { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
2414
+ .tcr-day-row { display: flex; gap: 6px; }
2415
+ .tcr-day { width: 34px; height: 34px; padding: 0; border: 1px solid var(--ta-border-field); border-radius: 50%; background: var(--ta-input); color: var(--ta-secondary); font: inherit; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; cursor: pointer; transition: background 120ms, border-color 120ms, color 120ms; }
2416
+ .tcr-day:hover:not([aria-pressed='true']) { border-color: var(--ta-border); color: var(--ta-text); }
2417
+ .tcr-day[aria-pressed='true'] { border-color: var(--ta-brand); background: var(--ta-brand); color: var(--ta-brand-text); }
2418
+ .tcr-day-presets { display: flex; gap: 4px; }
2419
+ .tcr-preset { height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
2420
+ .tcr-preset:hover { background: var(--ta-hover); color: var(--ta-text); }
2421
+ .tcr-preset[aria-pressed='true'] { background: var(--ta-chip); color: var(--ta-text); font-weight: 500; }
2422
+ .tcr-time-row { align-items: center; justify-content: space-between; }
2423
+ .tcr-time { width: 140px; flex: none; }
2424
+ .tcr-time-row .tcr-link { align-self: center; }
2425
+ .tcr-more-summary { margin-left: 6px; color: var(--ta-muted); }
2426
+ .tcr-hook { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 12px; border-radius: 10px; background: var(--ta-raised); min-width: 0; }
2427
+ .tcr-hook code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; font-size: calc(12px * var(--ta-font-scale)); color: var(--ta-text); }
2428
+ .tcr-hook-note { font-size: calc(12px * var(--ta-font-scale)); margin: -2px 2px 4px; }
1729
2429
  .tcr-preview.tcr-bad { background: color-mix(in srgb, var(--ta-red) 11%, transparent); color: var(--ta-red); }
1730
2430
  .tcr-folder { display: flex; align-items: center; gap: 8px; text-align: left; cursor: pointer; }
1731
2431
  .tcr-folder:hover { border-color: var(--ta-border); background: var(--ta-hover); }
@@ -1759,16 +2459,22 @@ var STYLE = `
1759
2459
  * so that the name is not cut to nothing by the rest; everything a finger taps is a finger's size.
1760
2460
  */
1761
2461
  [data-layout='compact'] .tcr-page { padding: 12px 10px 48px; }
1762
- [data-layout='compact'] .tcr-head { margin-bottom: 8px; min-height: 24px; }
2462
+ /* A phone: the control across the page, its parts of one width, as a phone's segmented controls. */
2463
+ [data-layout='compact'] .tcr-filters { display: grid; margin-bottom: 12px; }
2464
+ [data-layout='compact'] .tcr-group-title { margin-left: 4px; }
1763
2465
  [data-layout='compact'] .tcr-list { gap: 8px; }
1764
2466
  [data-layout='compact'] .tcr-task-row { gap: 2px; padding-right: 6px; }
1765
2467
  [data-layout='compact'] .tcr-task-main { gap: 10px; min-height: 68px; padding: 12px 2px 12px 12px; }
1766
2468
  [data-layout='compact'] .tcr-mark { width: 34px; height: 34px; }
1767
2469
  [data-layout='compact'] .tcr-task-name { font-size: calc(15px * var(--ta-font-scale)); }
1768
- [data-layout='compact'] .tcr-task-dir, [data-layout='compact'] .tcr-task-last { display: none; }
2470
+ /* The rule says when; what the row adds is a run that failed, or a task that runs, waits or is paused. */
2471
+ [data-layout='compact'] .tcr-task-dir, [data-layout='compact'] .tcr-task-last:not(.tcr-is-error) { display: none; }
1769
2472
  [data-layout='compact'] .tcr-task-state { display: none; }
1770
2473
  [data-layout='compact'] .tcr-task-next { display: inline; }
1771
- [data-layout='compact'] .tcr-chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
2474
+ [data-layout='compact'] .tcr-task-next.tcr-is-time { display: none; }
2475
+ [data-layout='compact'] .tcr-last-full { display: none; }
2476
+ [data-layout='compact'] .tcr-last-short { display: inline; }
2477
+ [data-layout='compact'] .tcr-task-rule { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
1772
2478
  [data-layout='compact'] .tcr-detail { margin: 0 12px; padding: 12px 0 14px; }
1773
2479
  [data-layout='compact'] .tcr-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px 14px; padding: 0 12px; }
1774
2480
  [data-layout='compact'] .tcr-stats { display: none; }
@@ -1797,8 +2503,9 @@ var STYLE = `
1797
2503
  [data-touch] .tcr-run-head:hover { background: none; }
1798
2504
  [data-touch] .tcr-run-head:active { background: var(--ta-hover); }
1799
2505
  [data-touch] .tcr-button { height: 36px; padding: 0 14px; }
1800
- [data-touch] .tcr-fold { min-height: 40px; font-size: max(15px, calc(13px * var(--ta-font-scale))); }
1801
- [data-touch] .tcr-fold:hover { background: none; }
2506
+ [data-touch] .tcr-filters button { height: 32px; }
2507
+ [data-touch] .tcr-day { width: 38px; height: 38px; }
2508
+ [data-touch] .tcr-preset { height: 34px; }
1802
2509
  [data-touch] .tcr-segment { height: 32px; }
1803
2510
  [data-touch] .tcr-more-toggle { padding: 8px 6px 8px 4px; font-size: max(15px, calc(13.5px * var(--ta-font-scale))); }
1804
2511
  /* A link of the dialog, which a finger taps too: a line of its own height. */
@@ -1822,13 +2529,15 @@ function injectStyle() {
1822
2529
  }
1823
2530
 
1824
2531
  // web-src/form-util.ts
1825
- function pad2(value) {
2532
+ var EVERY_DAY = [0, 1, 2, 3, 4, 5, 6];
2533
+ function pad3(value) {
1826
2534
  return String(value).padStart(2, "0");
1827
2535
  }
1828
2536
  var FormUtil;
1829
2537
  ((FormUtil) => {
2538
+ FormUtil.WEEKDAYS = [1, 2, 3, 4, 5];
1830
2539
  function localTime(date) {
1831
- return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
2540
+ return `${date.getFullYear()}-${pad3(date.getMonth() + 1)}-${pad3(date.getDate())}T${pad3(date.getHours())}:${pad3(date.getMinutes())}`;
1832
2541
  }
1833
2542
  FormUtil.localTime = localTime;
1834
2543
  function empty(cwd, now) {
@@ -1838,17 +2547,20 @@ var FormUtil;
1838
2547
  prompt: "",
1839
2548
  name: "",
1840
2549
  mode: "repeat",
1841
- repeat: "daily",
2550
+ event: "watch",
2551
+ watchPath: ".",
2552
+ repeat: "days",
1842
2553
  amount: 30,
1843
2554
  unit: "m",
1844
2555
  time: "09:00",
1845
- weekday: 1,
2556
+ days: EVERY_DAY,
1846
2557
  cron: "0 9 * * *",
1847
2558
  at: localTime(soon),
1848
2559
  cwd,
1849
2560
  notify: "",
1850
2561
  model: "",
1851
- thinking: ""
2562
+ thinking: "",
2563
+ timeout: ""
1852
2564
  };
1853
2565
  }
1854
2566
  FormUtil.empty = empty;
@@ -1860,7 +2572,8 @@ var FormUtil;
1860
2572
  cwd: task.cwd,
1861
2573
  notify: task.notify ?? "",
1862
2574
  model: task.model ?? "",
1863
- thinking: task.thinking ?? ""
2575
+ thinking: task.thinking ?? "",
2576
+ timeout: task.timeout ?? ""
1864
2577
  };
1865
2578
  return { ...form, ...ruleOf(task.schedule) };
1866
2579
  }
@@ -1869,49 +2582,51 @@ var FormUtil;
1869
2582
  if (schedule2.kind === "once") {
1870
2583
  return { mode: "once", at: localTime(new Date(schedule2.at)) };
1871
2584
  }
2585
+ if (schedule2.kind === "watch") {
2586
+ return { mode: "event", event: "watch", watchPath: schedule2.path };
2587
+ }
2588
+ if (schedule2.kind === "webhook") {
2589
+ return { mode: "event", event: "webhook" };
2590
+ }
1872
2591
  if (schedule2.kind === "interval") {
1873
2592
  const ms = Duration.parse(schedule2.every) ?? 30 * 60000;
1874
2593
  const [amount, unit] = ms % 86400000 === 0 ? [ms / 86400000, "d"] : ms % 3600000 === 0 ? [ms / 3600000, "h"] : [Math.round(ms / 60000), "m"];
1875
2594
  return { mode: "repeat", repeat: "every", amount, unit };
1876
2595
  }
1877
- const [minute, hour, day, month, weekday] = (NICKNAMES[schedule2.expression.toLowerCase()] ?? schedule2.expression).split(" ");
1878
- const simple = /^\d+$/.test(minute) && /^\d+$/.test(hour) && day === "*" && month === "*";
1879
- const time = `${pad2(Number(hour))}:${pad2(Number(minute))}`;
1880
- if (simple && weekday === "*") {
1881
- return { mode: "repeat", repeat: "daily", time, cron: schedule2.expression };
1882
- }
1883
- if (simple && weekday === "1-5") {
1884
- return { mode: "repeat", repeat: "weekdays", time, cron: schedule2.expression };
1885
- }
1886
- if (simple && /^[0-7]$/.test(weekday)) {
1887
- return { mode: "repeat", repeat: "weekly", time, weekday: Number(weekday) % 7, cron: schedule2.expression };
1888
- }
1889
- return { mode: "repeat", repeat: "custom", cron: schedule2.expression };
2596
+ const daily = When.timeAndDays(schedule2.expression);
2597
+ return daily ? { mode: "repeat", repeat: "days", time: daily.time, days: daily.days, cron: schedule2.expression } : { mode: "repeat", repeat: "custom", cron: schedule2.expression };
1890
2598
  }
1891
2599
  function schedule(form) {
1892
2600
  if (form.mode === "once") {
1893
2601
  return ScheduleUtil.check({ kind: "once", at: form.at });
1894
2602
  }
1895
- const time = /^(\d{1,2}):(\d{2})$/.exec(form.time);
1896
- const [hour, minute] = time ? [Number(time[1]), Number(time[2])] : [9, 0];
2603
+ if (form.mode === "event") {
2604
+ return ScheduleUtil.check(form.event === "webhook" ? { kind: "webhook" } : { kind: "watch", path: form.watchPath });
2605
+ }
1897
2606
  switch (form.repeat) {
1898
2607
  case "every":
1899
2608
  return ScheduleUtil.check({ kind: "interval", every: `${Math.max(1, Math.floor(form.amount || 0))}${form.unit}` });
1900
- case "daily":
1901
- return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * *` });
1902
- case "weekdays":
1903
- return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * 1-5` });
1904
- case "weekly":
1905
- return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * ${form.weekday}` });
1906
2609
  case "custom":
1907
2610
  return ScheduleUtil.check({ kind: "cron", expression: form.cron });
2611
+ case "days": {
2612
+ if (form.days.length === 0) {
2613
+ throw new Error("");
2614
+ }
2615
+ const time = /^(\d{1,2}):(\d{2})$/.exec(form.time);
2616
+ const [hour, minute] = time ? [Number(time[1]), Number(time[2])] : [9, 0];
2617
+ return ScheduleUtil.check({ kind: "cron", expression: `${minute} ${hour} * * ${WeekDays.field(form.days)}` });
2618
+ }
1908
2619
  }
1909
2620
  }
1910
2621
  FormUtil.schedule = schedule;
1911
2622
  function preview(form, now) {
1912
2623
  try {
1913
- const next = ScheduleUtil.next(schedule(form), now);
1914
- return next ? { next } : { error: "" };
2624
+ const rule = schedule(form);
2625
+ if (ScheduleUtil.isEvent(rule)) {
2626
+ return { event: true };
2627
+ }
2628
+ const next = When.nextTimes(rule, now, 3);
2629
+ return next.length ? { next } : { error: "" };
1915
2630
  } catch (error) {
1916
2631
  return { error: error instanceof Error ? error.message : String(error) };
1917
2632
  }
@@ -1925,14 +2640,14 @@ var FormUtil;
1925
2640
  cwd: form.cwd || undefined,
1926
2641
  model: form.model || undefined,
1927
2642
  thinking: form.thinking || undefined,
1928
- notify: form.notify || undefined
2643
+ notify: form.notify || undefined,
2644
+ timeout: form.timeout || undefined
1929
2645
  };
1930
2646
  }
1931
2647
  FormUtil.input = input;
1932
2648
  })(FormUtil ||= {});
1933
2649
 
1934
2650
  // web-src/editor.tsx
1935
- var REPEATS = ["every", "daily", "weekdays", "weekly", "custom"];
1936
2651
  var UNITS2 = [
1937
2652
  ["m", "minutes"],
1938
2653
  ["h", "hours"],
@@ -1944,19 +2659,21 @@ var NOTIFY = [
1944
2659
  ["error", "notifyError"],
1945
2660
  ["never", "notifyNever"]
1946
2661
  ];
1947
- var DAY_NAMES = new Map;
2662
+ var TIMEOUTS = ["15m", "1h", "2h", "4h"];
2663
+ var WEEK = [1, 2, 3, 4, 5, 6, 0];
2664
+ var DAY_NAMES2 = new Map;
1948
2665
  function weekdayNames() {
1949
2666
  const language = pi.ui.language;
1950
- let names = DAY_NAMES.get(language);
2667
+ let names = DAY_NAMES2.get(language);
1951
2668
  if (!names) {
1952
- const format = new Intl.DateTimeFormat(language, { weekday: "short" });
2669
+ const format = new Intl.DateTimeFormat(language, { weekday: TaLanguageUtil.cjk(language) ? "narrow" : "short" });
1953
2670
  names = Array.from({ length: 7 }, (_, day) => format.format(new Date(2023, 0, 1 + day)));
1954
- DAY_NAMES.set(language, names);
2671
+ DAY_NAMES2.set(language, names);
1955
2672
  }
1956
2673
  return names;
1957
2674
  }
1958
2675
  function ruleKey(form) {
1959
- return [form.mode, form.repeat, form.amount, form.unit, form.time, form.weekday, form.cron, form.at].join("|");
2676
+ return [form.mode, form.repeat, form.event, form.watchPath, form.amount, form.unit, form.time, form.days.join(","), form.cron, form.at].join("|");
1960
2677
  }
1961
2678
  function usePreview(form) {
1962
2679
  const key = ruleKey(form);
@@ -1973,7 +2690,36 @@ function Segments({ value, options, onChange }) {
1973
2690
  onClick: () => onChange(key)
1974
2691
  }, label)));
1975
2692
  }
1976
- function ModelFields({ form, set, cwd }) {
2693
+ function DayPicker({ days, onChange }) {
2694
+ const names = weekdayNames();
2695
+ const same = (other) => days.length === other.length && other.every((day) => days.includes(day));
2696
+ const toggle = (day) => onChange(days.includes(day) ? days.filter((other) => other !== day) : [...days, day]);
2697
+ return /* @__PURE__ */ React.createElement("div", {
2698
+ className: "tcr-days"
2699
+ }, /* @__PURE__ */ React.createElement("div", {
2700
+ className: "tcr-day-row"
2701
+ }, WEEK.map((day) => /* @__PURE__ */ React.createElement("button", {
2702
+ key: day,
2703
+ type: "button",
2704
+ className: "tcr-day",
2705
+ "aria-pressed": days.includes(day),
2706
+ onClick: () => toggle(day)
2707
+ }, names[day]))), /* @__PURE__ */ React.createElement("div", {
2708
+ className: "tcr-day-presets"
2709
+ }, /* @__PURE__ */ React.createElement("button", {
2710
+ type: "button",
2711
+ className: "tcr-preset",
2712
+ "aria-pressed": same([0, 1, 2, 3, 4, 5, 6]),
2713
+ onClick: () => onChange([0, 1, 2, 3, 4, 5, 6])
2714
+ }, t("daily")), /* @__PURE__ */ React.createElement("button", {
2715
+ type: "button",
2716
+ className: "tcr-preset",
2717
+ "aria-pressed": same(FormUtil.WEEKDAYS),
2718
+ onClick: () => onChange(FormUtil.WEEKDAYS)
2719
+ }, t("weekdays"))));
2720
+ }
2721
+ function MoreFields({ form, set, cwd }) {
2722
+ const timeouts = form.timeout && !TIMEOUTS.includes(form.timeout) ? [...TIMEOUTS, form.timeout] : TIMEOUTS;
1977
2723
  return /* @__PURE__ */ React.createElement("div", {
1978
2724
  className: "tcr-grid"
1979
2725
  }, /* @__PURE__ */ React.createElement("div", {
@@ -1999,13 +2745,62 @@ function ModelFields({ form, set, cwd }) {
1999
2745
  }, t("notifyDefault")), THINKING_LEVELS.map((level) => /* @__PURE__ */ React.createElement("option", {
2000
2746
  key: level,
2001
2747
  value: level
2002
- }, level)))));
2748
+ }, level)))), /* @__PURE__ */ React.createElement("label", {
2749
+ className: "tcr-field"
2750
+ }, /* @__PURE__ */ React.createElement("span", {
2751
+ className: "tcr-label"
2752
+ }, t("timeoutLabel")), /* @__PURE__ */ React.createElement("select", {
2753
+ className: "tcr-input",
2754
+ name: "timeout",
2755
+ value: form.timeout,
2756
+ onChange: (event) => set({ timeout: event.target.value })
2757
+ }, /* @__PURE__ */ React.createElement("option", {
2758
+ value: ""
2759
+ }, t("timeoutDefault")), timeouts.map((timeout) => /* @__PURE__ */ React.createElement("option", {
2760
+ key: timeout,
2761
+ value: timeout
2762
+ }, length(timeout))))), /* @__PURE__ */ React.createElement("label", {
2763
+ className: "tcr-field"
2764
+ }, /* @__PURE__ */ React.createElement("span", {
2765
+ className: "tcr-label"
2766
+ }, t("notify")), /* @__PURE__ */ React.createElement("select", {
2767
+ className: "tcr-input",
2768
+ value: form.notify,
2769
+ onChange: (event) => set({ notify: event.target.value })
2770
+ }, NOTIFY.map(([level, word]) => /* @__PURE__ */ React.createElement("option", {
2771
+ key: level,
2772
+ value: level
2773
+ }, t(word))))), /* @__PURE__ */ React.createElement("label", {
2774
+ className: "tcr-field tcr-wide"
2775
+ }, /* @__PURE__ */ React.createElement("span", {
2776
+ className: "tcr-label"
2777
+ }, t("name")), /* @__PURE__ */ React.createElement("input", {
2778
+ className: "tcr-input",
2779
+ value: form.name,
2780
+ placeholder: t("namePlaceholder"),
2781
+ onChange: (event) => set({ name: event.target.value })
2782
+ })));
2783
+ }
2784
+ function moreSummary(form) {
2785
+ return [
2786
+ form.model?.split("/").pop(),
2787
+ form.thinking,
2788
+ form.timeout && t("timeoutIs", { time: length(form.timeout) }),
2789
+ form.notify && t(NOTIFY.find(([level]) => level === form.notify)?.[1] ?? "notifyDefault")
2790
+ ].filter(Boolean).join(" · ");
2003
2791
  }
2004
- function When({ form, set }) {
2792
+ function When2({ form, set }) {
2005
2793
  const preview = usePreview(form);
2006
- const days = weekdayNames();
2007
2794
  let rule = null;
2008
- if (form.mode === "once") {
2795
+ if (form.mode === "event") {
2796
+ rule = form.event === "watch" ? /* @__PURE__ */ React.createElement("input", {
2797
+ className: "tcr-input tcr-mono",
2798
+ value: form.watchPath,
2799
+ placeholder: t("watchPlaceholder"),
2800
+ "aria-label": t("watchPath"),
2801
+ onChange: (event) => set({ watchPath: event.target.value })
2802
+ }) : null;
2803
+ } else if (form.mode === "once") {
2009
2804
  rule = /* @__PURE__ */ React.createElement("input", {
2010
2805
  className: "tcr-input",
2011
2806
  type: "datetime-local",
@@ -2030,33 +2825,47 @@ function When({ form, set }) {
2030
2825
  value: unit
2031
2826
  }, t(word)))));
2032
2827
  } else if (form.repeat === "custom") {
2033
- rule = /* @__PURE__ */ React.createElement("input", {
2828
+ rule = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("input", {
2034
2829
  className: "tcr-input tcr-mono",
2035
2830
  value: form.cron,
2036
2831
  placeholder: "0 9 * * 1-5",
2832
+ "aria-label": "cron",
2037
2833
  onChange: (event) => set({ cron: event.target.value })
2038
- });
2834
+ }), /* @__PURE__ */ React.createElement("button", {
2835
+ type: "button",
2836
+ className: "tcr-link",
2837
+ onClick: () => set({ repeat: "days" })
2838
+ }, t("useDays")));
2039
2839
  } else {
2040
- rule = /* @__PURE__ */ React.createElement("div", {
2041
- className: "tcr-row"
2042
- }, form.repeat === "weekly" && /* @__PURE__ */ React.createElement("select", {
2043
- className: "tcr-input",
2044
- value: form.weekday,
2045
- onChange: (event) => set({ weekday: Number(event.target.value) })
2046
- }, days.map((day, index) => /* @__PURE__ */ React.createElement("option", {
2047
- key: day,
2048
- value: index
2049
- }, day))), /* @__PURE__ */ React.createElement("input", {
2050
- className: "tcr-input",
2840
+ rule = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DayPicker, {
2841
+ days: form.days,
2842
+ onChange: (days) => set({ days })
2843
+ }), /* @__PURE__ */ React.createElement("div", {
2844
+ className: "tcr-row tcr-time-row"
2845
+ }, /* @__PURE__ */ React.createElement("input", {
2846
+ className: "tcr-input tcr-time",
2051
2847
  type: "time",
2052
2848
  value: form.time,
2849
+ "aria-label": t("atTime"),
2053
2850
  onChange: (event) => set({ time: event.target.value })
2054
- }));
2055
- }
2056
- const kind = form.mode === "once" ? "once" : form.repeat;
2057
- const kinds = [...REPEATS.map((repeat) => [repeat, t(repeat)]), ["once", t("once")]];
2058
- const Clock = icon("Clock");
2059
- const bad = !preview.next;
2851
+ }), /* @__PURE__ */ React.createElement("button", {
2852
+ type: "button",
2853
+ className: "tcr-link",
2854
+ onClick: () => set({ repeat: "custom" })
2855
+ }, t("useCron"))));
2856
+ }
2857
+ const kind = form.mode === "once" ? "once" : form.mode === "event" ? form.event : form.repeat === "every" ? "every" : "days";
2858
+ const kinds = [
2859
+ ["days", t("atTimes")],
2860
+ ["every", t("every")],
2861
+ ["once", t("once")],
2862
+ ["watch", t("onWatch")],
2863
+ ["webhook", t("onWebhook")]
2864
+ ];
2865
+ const pick = (next) => set(next === "once" ? { mode: "once" } : next === "watch" || next === "webhook" ? { mode: "event", event: next } : { mode: "repeat", repeat: next === "every" ? "every" : form.repeat === "custom" ? "custom" : "days" });
2866
+ const Clock = icon(preview.event ? "Zap" : "Clock");
2867
+ const bad = !preview.next && !preview.event;
2868
+ const now = new Date;
2060
2869
  return /* @__PURE__ */ React.createElement("div", {
2061
2870
  className: "tcr-field"
2062
2871
  }, /* @__PURE__ */ React.createElement("div", {
@@ -2064,13 +2873,13 @@ function When({ form, set }) {
2064
2873
  }, t("when")), /* @__PURE__ */ React.createElement(Segments, {
2065
2874
  value: kind,
2066
2875
  options: kinds,
2067
- onChange: (next) => set(next === "once" ? { mode: "once" } : { mode: "repeat", repeat: next })
2876
+ onChange: pick
2068
2877
  }), rule, /* @__PURE__ */ React.createElement("div", {
2069
2878
  className: `tcr-preview${bad ? " tcr-bad" : ""}`,
2070
2879
  role: "status"
2071
2880
  }, /* @__PURE__ */ React.createElement(Clock, {
2072
2881
  size: 13
2073
- }), preview.next ? t("preview", { time: ScheduleUtil.clock(preview.next) }) : preview.error || t("noNext")));
2882
+ }), preview.event ? t(form.event === "webhook" ? "webhookHint" : "watchHint") : preview.next ? t("preview", { time: preview.next.map((time) => ScheduleUtil.clock(time, now)).join(" · ") }) : preview.error || t(form.mode === "repeat" && form.repeat === "days" && form.days.length === 0 ? "pickDays" : "noNext")));
2074
2883
  }
2075
2884
  function TaskEditor({ client, editing, onClose }) {
2076
2885
  const Dialog = pi.ui.Dialog;
@@ -2082,15 +2891,21 @@ function TaskEditor({ client, editing, onClose }) {
2082
2891
  return FormUtil.fromTask(editing.task, now);
2083
2892
  }
2084
2893
  const empty = FormUtil.empty(cwd, now);
2085
- return { ...empty, prompt: editing.prompt ?? "", repeat: editing.repeat ?? empty.repeat };
2894
+ return {
2895
+ ...empty,
2896
+ prompt: editing.prompt ?? "",
2897
+ repeat: editing.repeat ?? empty.repeat,
2898
+ days: editing.days ?? empty.days,
2899
+ time: editing.time ?? empty.time
2900
+ };
2086
2901
  });
2087
2902
  const [picking, setPicking] = React.useState(false);
2088
- const [more, setMore] = React.useState(!!(form.name && editing.task) || !!form.notify);
2903
+ const [more, setMore] = React.useState(false);
2089
2904
  const [saving, setSaving] = React.useState(false);
2090
2905
  const touch = pi.ui.useDevice().touch;
2091
2906
  const set = (change) => setForm((current) => ({ ...current, ...change }));
2092
2907
  const preview = usePreview(form);
2093
- const valid = form.prompt.trim().length > 0 && !!preview.next;
2908
+ const valid = form.prompt.trim().length > 0 && (!!preview.next || !!preview.event);
2094
2909
  const save = async () => {
2095
2910
  if (!valid || saving) {
2096
2911
  return;
@@ -2099,7 +2914,14 @@ function TaskEditor({ client, editing, onClose }) {
2099
2914
  try {
2100
2915
  const input = FormUtil.input(form);
2101
2916
  if (editing.task) {
2102
- await client.update(editing.task.id, { ...input, name: form.name, model: form.model, thinking: form.thinking, notify: form.notify });
2917
+ await client.update(editing.task.id, {
2918
+ ...input,
2919
+ name: form.name,
2920
+ model: form.model,
2921
+ thinking: form.thinking,
2922
+ notify: form.notify,
2923
+ timeout: form.timeout
2924
+ });
2103
2925
  } else {
2104
2926
  await client.add(input);
2105
2927
  if (typeof Notification !== "undefined" && Notification.permission === "default") {
@@ -2137,7 +2959,7 @@ function TaskEditor({ client, editing, onClose }) {
2137
2959
  autoFocus: !touch,
2138
2960
  onChange: (event) => set({ prompt: event.target.value }),
2139
2961
  onKeyDown: (event) => (event.metaKey || event.ctrlKey) && event.key === "Enter" && void save()
2140
- })), /* @__PURE__ */ React.createElement(When, {
2962
+ })), /* @__PURE__ */ React.createElement(When2, {
2141
2963
  form,
2142
2964
  set
2143
2965
  }), /* @__PURE__ */ React.createElement("div", {
@@ -2155,11 +2977,7 @@ function TaskEditor({ client, editing, onClose }) {
2155
2977
  className: "tcr-folder-name"
2156
2978
  }, basename(form.cwd || cwd)), /* @__PURE__ */ React.createElement("span", {
2157
2979
  className: "tcr-folder-path"
2158
- }, `‎${form.cwd || cwd}‎`))), /* @__PURE__ */ React.createElement(ModelFields, {
2159
- form,
2160
- set,
2161
- cwd: form.cwd || cwd
2162
- }), /* @__PURE__ */ React.createElement("div", {
2980
+ }, `‎${form.cwd || cwd}‎`))), /* @__PURE__ */ React.createElement("div", {
2163
2981
  className: `tcr-options${more ? " tcr-open" : ""}`
2164
2982
  }, /* @__PURE__ */ React.createElement("button", {
2165
2983
  type: "button",
@@ -2171,29 +2989,13 @@ function TaskEditor({ client, editing, onClose }) {
2171
2989
  "aria-hidden": "true"
2172
2990
  }, /* @__PURE__ */ React.createElement(Chevron, {
2173
2991
  size: 14
2174
- })), t("moreOptions")), more && /* @__PURE__ */ React.createElement("div", {
2175
- className: "tcr-grid"
2176
- }, /* @__PURE__ */ React.createElement("label", {
2177
- className: "tcr-field"
2178
- }, /* @__PURE__ */ React.createElement("span", {
2179
- className: "tcr-label"
2180
- }, t("name")), /* @__PURE__ */ React.createElement("input", {
2181
- className: "tcr-input",
2182
- value: form.name,
2183
- placeholder: t("namePlaceholder"),
2184
- onChange: (event) => set({ name: event.target.value })
2185
- })), /* @__PURE__ */ React.createElement("label", {
2186
- className: "tcr-field"
2187
- }, /* @__PURE__ */ React.createElement("span", {
2188
- className: "tcr-label"
2189
- }, t("notify")), /* @__PURE__ */ React.createElement("select", {
2190
- className: "tcr-input",
2191
- value: form.notify,
2192
- onChange: (event) => set({ notify: event.target.value })
2193
- }, NOTIFY.map(([level, word]) => /* @__PURE__ */ React.createElement("option", {
2194
- key: level,
2195
- value: level
2196
- }, t(word)))))))), /* @__PURE__ */ React.createElement("div", {
2992
+ })), t("moreOptions"), !more && moreSummary(form) && /* @__PURE__ */ React.createElement("span", {
2993
+ className: "tcr-more-summary"
2994
+ }, moreSummary(form))), more && /* @__PURE__ */ React.createElement(MoreFields, {
2995
+ form,
2996
+ set,
2997
+ cwd: form.cwd || cwd
2998
+ }))), /* @__PURE__ */ React.createElement("div", {
2197
2999
  className: "tcr-actions"
2198
3000
  }, !touch && /* @__PURE__ */ React.createElement("span", {
2199
3001
  className: "tcr-shortcut"
@@ -2323,6 +3125,67 @@ function ExampleArt({ picture }) {
2323
3125
  return /* @__PURE__ */ React.createElement(Picture, null, /* @__PURE__ */ React.createElement(Shapes, null));
2324
3126
  }
2325
3127
 
3128
+ // web-src/task-list.ts
3129
+ var DAY_MS = 86400000;
3130
+ var GROUPS = ["running", "today", "tomorrow", "week", "later", "event", "done"];
3131
+ var TaskList;
3132
+ ((TaskList) => {
3133
+ function failed(task) {
3134
+ return task.lastStatus === "error" || task.lastStatus === "missed";
3135
+ }
3136
+ TaskList.failed = failed;
3137
+ function on(task, stay = new Set) {
3138
+ return task.enabled || task.lastStatus === "running" || stay.has(task.id);
3139
+ }
3140
+ TaskList.on = on;
3141
+ function counts(tasks, stay) {
3142
+ return {
3143
+ on: tasks.filter((task) => on(task, stay)).length,
3144
+ failed: tasks.filter(failed).length,
3145
+ off: tasks.filter((task) => !on(task, stay)).length,
3146
+ running: tasks.filter((task) => task.lastStatus === "running").length
3147
+ };
3148
+ }
3149
+ TaskList.counts = counts;
3150
+ function filter(tasks, filter2, stay) {
3151
+ const test = filter2 === "failed" ? failed : filter2 === "off" ? (task) => !on(task, stay) : (task) => on(task, stay);
3152
+ return [...tasks].filter(test).sort((a, b) => at(a) - at(b) || a.name.localeCompare(b.name));
3153
+ }
3154
+ TaskList.filter = filter;
3155
+ function group(task, now) {
3156
+ if (task.lastStatus === "running") {
3157
+ return "running";
3158
+ }
3159
+ if (ScheduleUtil.isEvent(task.schedule)) {
3160
+ return task.enabled ? "event" : "done";
3161
+ }
3162
+ if (!task.nextRunAt || !task.enabled) {
3163
+ return "done";
3164
+ }
3165
+ const days = Math.floor((startOfDay(new Date(task.nextRunAt)) - startOfDay(now)) / DAY_MS);
3166
+ return days <= 0 ? "today" : days === 1 ? "tomorrow" : days < 7 ? "week" : "later";
3167
+ }
3168
+ TaskList.group = group;
3169
+ function groups(tasks, now) {
3170
+ const by = new Map;
3171
+ for (const task of tasks) {
3172
+ const key = group(task, now);
3173
+ by.set(key, [...by.get(key) ?? [], task]);
3174
+ }
3175
+ return GROUPS.filter((key) => by.has(key)).map((key) => ({ group: key, tasks: by.get(key) }));
3176
+ }
3177
+ TaskList.groups = groups;
3178
+ function at(task) {
3179
+ if (task.lastStatus === "running") {
3180
+ return 0;
3181
+ }
3182
+ return task.enabled && task.nextRunAt ? new Date(task.nextRunAt).getTime() : Number.MAX_SAFE_INTEGER;
3183
+ }
3184
+ function startOfDay(date) {
3185
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
3186
+ }
3187
+ })(TaskList ||= {});
3188
+
2326
3189
  // web-src/task-util.ts
2327
3190
  var PROMPT_MAX3 = 20000;
2328
3191
  var NAME_MAX = 80;
@@ -2335,9 +3198,28 @@ var TaskUtil;
2335
3198
  return `${prefix}_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
2336
3199
  }
2337
3200
  TaskUtil.newId = newId;
3201
+ function newSecret() {
3202
+ const bytes = new Uint8Array(24);
3203
+ crypto.getRandomValues(bytes);
3204
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3205
+ }
3206
+ TaskUtil.newSecret = newSecret;
3207
+ function withSecret(task) {
3208
+ if (task.schedule.kind === "webhook") {
3209
+ return task.hookSecret ? task : { ...task, hookSecret: newSecret() };
3210
+ }
3211
+ if (!task.hookSecret) {
3212
+ return task;
3213
+ }
3214
+ const { hookSecret: _gone, ...rest } = task;
3215
+ return rest;
3216
+ }
2338
3217
  function create(input, cwd, now) {
2339
3218
  const prompt = checkPrompt(input?.prompt);
2340
- const schedule = ScheduleUtil.check(input.schedule);
3219
+ const schedule = ruleOf(input, now);
3220
+ if (!schedule) {
3221
+ throw new Error(`A task needs when it runs: when, one of ${WHEN_FORMS}.`);
3222
+ }
2341
3223
  const at = now.toISOString();
2342
3224
  const task = {
2343
3225
  id: newId("task"),
@@ -2352,7 +3234,7 @@ var TaskUtil;
2352
3234
  updatedAt: at
2353
3235
  };
2354
3236
  setOptional(task, input);
2355
- return arm(task, now);
3237
+ return arm(withSecret(task), now);
2356
3238
  }
2357
3239
  TaskUtil.create = create;
2358
3240
  function patch(task, patch2, now) {
@@ -2370,17 +3252,37 @@ var TaskUtil;
2370
3252
  if (patch2.enabled !== undefined) {
2371
3253
  next.enabled = patch2.enabled === true;
2372
3254
  }
2373
- if (patch2.schedule !== undefined) {
2374
- next.schedule = ScheduleUtil.check(patch2.schedule);
3255
+ const schedule = ruleOf(patch2, now);
3256
+ if (schedule) {
3257
+ next.schedule = schedule;
2375
3258
  }
2376
- const rearm = patch2.schedule !== undefined || next.enabled && !task.enabled;
2377
- return rearm ? arm(next, now) : next;
3259
+ const rearm = schedule !== undefined || next.enabled && !task.enabled;
3260
+ const secured = withSecret(next);
3261
+ return rearm ? arm(secured, now) : secured;
2378
3262
  }
2379
3263
  TaskUtil.patch = patch;
3264
+ function unique(tasks, task, named) {
3265
+ const twin = named ? tasks.find((other) => other.name === task.name && other.cwd === task.cwd) : undefined;
3266
+ if (twin) {
3267
+ throw new Error(`A task named ${JSON.stringify(twin.name)} is already in ${twin.cwd} (${twin.id}): change it with update, or give the new one another name.`);
3268
+ }
3269
+ }
3270
+ TaskUtil.unique = unique;
3271
+ function ruleOf(input, now) {
3272
+ if (typeof input?.when === "string" && input.when.trim()) {
3273
+ return When.parse(input.when, now);
3274
+ }
3275
+ return input?.schedule === undefined ? undefined : ScheduleUtil.check(input.schedule);
3276
+ }
3277
+ TaskUtil.ruleOf = ruleOf;
2380
3278
  function arm(task, now) {
2381
3279
  if (!task.enabled) {
2382
3280
  return task;
2383
3281
  }
3282
+ if (ScheduleUtil.isEvent(task.schedule)) {
3283
+ const { nextRunAt: _none, ...rest } = task;
3284
+ return rest;
3285
+ }
2384
3286
  const next = ScheduleUtil.next(task.schedule, now);
2385
3287
  if (!next) {
2386
3288
  throw new Error(task.schedule.kind === "once" ? `The time of ${task.name} (${task.schedule.at}) has passed: give it a time to come.` : `The rule of ${task.name} never comes round: check the cron expression.`);
@@ -2463,6 +3365,11 @@ var TaskUtil;
2463
3365
  }
2464
3366
  return level || undefined;
2465
3367
  }
3368
+ function wrapUp(timeoutMs2, wrapUpMs) {
3369
+ const minutes = (ms) => Math.max(1, Math.round(ms / 60000));
3370
+ return TaMessageSource.notice(`This scheduled run has reached its time limit of ${minutes(timeoutMs2)} minutes. Start nothing new. Within ${minutes(wrapUpMs)} minutes, wrap up: keep what is done and checked, leave what is not as it is safe to leave, and answer with where it stands and what is left; after that the run is stopped.`, NAME);
3371
+ }
3372
+ TaskUtil.wrapUp = wrapUp;
2466
3373
  function timeoutMs(task, fallback) {
2467
3374
  return task.timeout && Duration.parse(task.timeout) || fallback;
2468
3375
  }
@@ -2493,33 +3400,16 @@ var TaskUtil;
2493
3400
  return line.replace(/^\s*(?:#{1,6}\s+|[-*+]\s+|>\s*|\d+[.)]\s+)/, "").replace(/\*\*|__|`/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
2494
3401
  }
2495
3402
  TaskUtil.firstLine = firstLine;
2496
- function split(tasks, stay = new Set) {
2497
- const listed = [];
2498
- const off = [];
2499
- for (const task of tasks) {
2500
- (task.enabled || task.lastStatus === "running" || stay.has(task.id) ? listed : off).push(task);
2501
- }
2502
- return [listed, off];
2503
- }
2504
- TaskUtil.split = split;
2505
3403
  function missed(task, now) {
2506
3404
  return task.schedule.kind === "once" && !!task.nextRunAt && now.getTime() - new Date(task.nextRunAt).getTime() > Limits.GRACE_MS;
2507
3405
  }
2508
3406
  TaskUtil.missed = missed;
2509
3407
  })(TaskUtil ||= {});
2510
3408
 
2511
- // web-src/tasks-view.tsx
3409
+ // web-src/task-row.tsx
2512
3410
  function useClient(client) {
2513
3411
  return React.useSyncExternalStore((listener) => client.subscribe(listener), () => client.state);
2514
3412
  }
2515
- function useMinute() {
2516
- const [now, setNow] = React.useState(Date.now());
2517
- React.useEffect(() => {
2518
- const timer = setInterval(() => setNow(Date.now()), 30000);
2519
- return () => clearInterval(timer);
2520
- }, []);
2521
- return now;
2522
- }
2523
3413
  async function guard(action) {
2524
3414
  try {
2525
3415
  await action();
@@ -2532,74 +3422,6 @@ function Dot({ status, enabled = true }) {
2532
3422
  className: `tcr-dot tcr-${enabled ? status ?? "idle" : "off"}`
2533
3423
  });
2534
3424
  }
2535
- function Clock2() {
2536
- return /* @__PURE__ */ React.createElement("svg", {
2537
- className: "tcr-clock",
2538
- viewBox: "0 0 120 120",
2539
- "aria-hidden": "true"
2540
- }, /* @__PURE__ */ React.createElement("circle", {
2541
- cx: "60",
2542
- cy: "60",
2543
- r: "44",
2544
- className: "tcr-clock-face"
2545
- }), Array.from({ length: 12 }, (_, hour) => /* @__PURE__ */ React.createElement("line", {
2546
- key: hour,
2547
- x1: "60",
2548
- y1: "22",
2549
- x2: "60",
2550
- y2: hour % 3 === 0 ? 29 : 26,
2551
- className: "tcr-clock-tick",
2552
- transform: `rotate(${hour * 30} 60 60)`
2553
- })), /* @__PURE__ */ React.createElement("line", {
2554
- x1: "60",
2555
- y1: "60",
2556
- x2: "60",
2557
- y2: "38",
2558
- className: "tcr-clock-hour"
2559
- }), /* @__PURE__ */ React.createElement("line", {
2560
- x1: "60",
2561
- y1: "60",
2562
- x2: "60",
2563
- y2: "28",
2564
- className: "tcr-clock-hand"
2565
- }), /* @__PURE__ */ React.createElement("circle", {
2566
- cx: "60",
2567
- cy: "60",
2568
- r: "3.5",
2569
- className: "tcr-clock-pin"
2570
- }));
2571
- }
2572
- var EXAMPLES = [
2573
- { text: "example1", repeat: "daily", rule: "0 9 * * *", picture: "commits" },
2574
- { text: "example2", repeat: "every", rule: "30m", picture: "checks" },
2575
- { text: "example3", repeat: "weekdays", rule: "0 18 * * 1-5", picture: "report" }
2576
- ];
2577
- function Empty({ onPick }) {
2578
- const PictureCards = pi.ui.PictureCards;
2579
- const cards = EXAMPLES.map((example) => {
2580
- const schedule = example.repeat === "every" ? { kind: "interval", every: example.rule } : { kind: "cron", expression: example.rule };
2581
- return {
2582
- key: example.text,
2583
- picture: /* @__PURE__ */ React.createElement(ExampleArt, {
2584
- picture: example.picture
2585
- }),
2586
- label: t(example.text),
2587
- hint: ScheduleUtil.describe(schedule, pi.ui.language),
2588
- onPick: () => onPick({ prompt: t(example.text), repeat: example.repeat })
2589
- };
2590
- });
2591
- return /* @__PURE__ */ React.createElement("div", {
2592
- className: "tcr-empty"
2593
- }, /* @__PURE__ */ React.createElement(Clock2, null), /* @__PURE__ */ React.createElement("div", {
2594
- className: "tcr-empty-title"
2595
- }, t("emptyTitle")), /* @__PURE__ */ React.createElement("div", {
2596
- className: "tcr-empty-hint"
2597
- }, t("emptyHint")), /* @__PURE__ */ React.createElement("div", {
2598
- className: "tcr-examples"
2599
- }, /* @__PURE__ */ React.createElement(PictureCards, {
2600
- cards
2601
- })));
2602
- }
2603
3425
  function outcome(run) {
2604
3426
  if (run.status === "missed") {
2605
3427
  return t("missedText");
@@ -2609,6 +3431,40 @@ function outcome(run) {
2609
3431
  }
2610
3432
  return run.error ?? run.summary;
2611
3433
  }
3434
+ function HookAddress({ client, task }) {
3435
+ const [url, setUrl] = React.useState();
3436
+ React.useEffect(() => {
3437
+ let current = true;
3438
+ client.call("hookUrl", task.id).then((next) => current && setUrl(next), () => {
3439
+ return;
3440
+ });
3441
+ return () => {
3442
+ current = false;
3443
+ };
3444
+ }, [client, task.id, task.hookSecret]);
3445
+ const Copy = icon("Copy");
3446
+ const command = url && `curl -X POST ${url} -d 'what happened'`;
3447
+ const copy = (text) => void navigator.clipboard?.writeText(text).then(() => pi.ui.notify(t("copied"), "info"), () => {
3448
+ return;
3449
+ });
3450
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
3451
+ className: "tcr-label"
3452
+ }, t("webhookLabel")), /* @__PURE__ */ React.createElement("div", {
3453
+ className: "tcr-hook"
3454
+ }, /* @__PURE__ */ React.createElement("code", {
3455
+ className: "tcr-mono"
3456
+ }, command ?? "…"), command && /* @__PURE__ */ React.createElement("button", {
3457
+ type: "button",
3458
+ className: "tcr-icon",
3459
+ "aria-label": t("copy"),
3460
+ title: t("copy"),
3461
+ onClick: () => copy(command)
3462
+ }, /* @__PURE__ */ React.createElement(Copy, {
3463
+ size: 14
3464
+ }))), /* @__PURE__ */ React.createElement("div", {
3465
+ className: "tcr-muted tcr-hook-note"
3466
+ }, t("webhookNote")));
3467
+ }
2612
3468
  function RunRow({ run, now, last }) {
2613
3469
  const [open, setOpen] = React.useState(false);
2614
3470
  const Markdown = pi.ui.Markdown;
@@ -2634,7 +3490,10 @@ function RunRow({ run, now, last }) {
2634
3490
  className: "tcr-muted"
2635
3491
  }, took), run.trigger === "manual" && /* @__PURE__ */ React.createElement("span", {
2636
3492
  className: "tcr-chip"
2637
- }, t("byHand")), /* @__PURE__ */ React.createElement("span", {
3493
+ }, t("byHand")), run.trigger === "event" && /* @__PURE__ */ React.createElement("span", {
3494
+ className: "tcr-chip",
3495
+ title: run.event
3496
+ }, t("byEvent")), /* @__PURE__ */ React.createElement("span", {
2638
3497
  className: "tcr-run-line"
2639
3498
  }, !open && text ? TaskUtil.firstLine(text) : ""), /* @__PURE__ */ React.createElement("span", {
2640
3499
  className: "tcr-chevron",
@@ -2678,7 +3537,60 @@ function PromptText({ text }) {
2678
3537
  onClick: () => setWhole(!whole)
2679
3538
  }, whole ? t("showLess") : t("showAll")));
2680
3539
  }
3540
+ function soon(time, now, grouped) {
3541
+ const clock = `${String(time.getHours()).padStart(2, "0")}:${String(time.getMinutes()).padStart(2, "0")}`;
3542
+ const day = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
3543
+ const days = Math.round((day(time) - day(now)) / 86400000);
3544
+ if (days <= 0 || grouped && days === 1) {
3545
+ return clock;
3546
+ }
3547
+ if (days === 1) {
3548
+ return t("tomorrowAt", { time: clock });
3549
+ }
3550
+ if (days < 7) {
3551
+ return `${new Intl.DateTimeFormat(pi.ui.language, { weekday: "short" }).format(time)} ${clock}`;
3552
+ }
3553
+ return ScheduleUtil.clock(time, now);
3554
+ }
3555
+ function stateOf(task, now, grouped) {
3556
+ if (task.lastStatus === "running") {
3557
+ return t("running");
3558
+ }
3559
+ if (!task.enabled) {
3560
+ return task.nextRunAt || ScheduleUtil.repeats(task.schedule) ? t("paused") : t("done");
3561
+ }
3562
+ if (task.nextRunAt) {
3563
+ return soon(new Date(task.nextRunAt), now, grouped);
3564
+ }
3565
+ return ScheduleUtil.isEvent(task.schedule) ? t("waitingEvent") : t("done");
3566
+ }
3567
+ function Facts({ task, now }) {
3568
+ const facts = [];
3569
+ if (task.enabled && task.nextRunAt) {
3570
+ facts.push(["factNext", ScheduleUtil.clock(new Date(task.nextRunAt), new Date(now))]);
3571
+ }
3572
+ facts.push(["factDir", basename(task.cwd), task.cwd]);
3573
+ facts.push(["factTimeout", length(task.timeout ?? "30m")]);
3574
+ if (task.model) {
3575
+ facts.push(["model", task.model.split("/").pop() ?? task.model, task.model]);
3576
+ }
3577
+ if (task.thinking) {
3578
+ facts.push(["thinking", task.thinking]);
3579
+ }
3580
+ const notify = ScheduleUtil.notifyLevel(task);
3581
+ facts.push(["notify", t(notify === "always" ? "notifyAlways" : notify === "error" ? "notifyError" : "notifyNever")]);
3582
+ return /* @__PURE__ */ React.createElement("div", {
3583
+ className: "tcr-facts"
3584
+ }, facts.map(([label, value, title]) => /* @__PURE__ */ React.createElement("span", {
3585
+ key: label,
3586
+ className: "tcr-fact",
3587
+ title
3588
+ }, /* @__PURE__ */ React.createElement("span", {
3589
+ className: "tcr-fact-label"
3590
+ }, t(label)), value)));
3591
+ }
2681
3592
  function Detail({ client, task, now, onEdit }) {
3593
+ const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
2682
3594
  const { runs } = useClient(client);
2683
3595
  React.useEffect(() => {
2684
3596
  client.loadRuns(task.id).catch(() => {
@@ -2688,7 +3600,6 @@ function Detail({ client, task, now, onEdit }) {
2688
3600
  const list = runs[task.id];
2689
3601
  const Play = icon("Play");
2690
3602
  const Pencil = icon("Pencil");
2691
- const Sparkles = icon("Sparkles");
2692
3603
  const Ask = icon("MessageCircle");
2693
3604
  const running = task.lastStatus === "running";
2694
3605
  const [starting, start] = useBusy(pi.ui);
@@ -2718,16 +3629,15 @@ function Detail({ client, task, now, onEdit }) {
2718
3629
  onClick: () => void changeTask(task, list)
2719
3630
  }, /* @__PURE__ */ React.createElement(Ask, {
2720
3631
  size: 14
2721
- }), t("change")), /* @__PURE__ */ React.createElement("button", {
2722
- type: "button",
2723
- className: "tcr-button tcr-accent",
2724
- title: t("makeExtensionHint"),
2725
- onClick: () => void makeExtension(task, list)
2726
- }, /* @__PURE__ */ React.createElement(Sparkles, {
2727
- size: 14
2728
- }), t("makeExtension")), task.runCount > 0 && /* @__PURE__ */ React.createElement("span", {
3632
+ }), t("change")), task.runCount > 0 && /* @__PURE__ */ React.createElement("span", {
2729
3633
  className: "tcr-stats"
2730
- }, t(task.failCount > 0 ? "statsFailed" : "stats", { runs: task.runCount, fails: task.failCount }))), /* @__PURE__ */ React.createElement("div", {
3634
+ }, t(task.failCount > 0 ? "statsFailed" : "stats", { runs: Math.max(task.runCount, task.failCount), fails: task.failCount }))), /* @__PURE__ */ React.createElement(Facts, {
3635
+ task,
3636
+ now
3637
+ }), task.schedule.kind === "webhook" && /* @__PURE__ */ React.createElement(HookAddress, {
3638
+ client,
3639
+ task
3640
+ }), /* @__PURE__ */ React.createElement("div", {
2731
3641
  className: "tcr-label"
2732
3642
  }, t("promptLabel")), /* @__PURE__ */ React.createElement(PromptText, {
2733
3643
  text: task.prompt
@@ -2735,8 +3645,8 @@ function Detail({ client, task, now, onEdit }) {
2735
3645
  className: "tcr-label"
2736
3646
  }, t("runs"), list && list.length > 0 && /* @__PURE__ */ React.createElement("span", {
2737
3647
  className: "tcr-count"
2738
- }, list.length)), list === undefined && /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
2739
- rows: 2
3648
+ }, list.length)), list === undefined && /* @__PURE__ */ React.createElement(Loading, {
3649
+ compact: true
2740
3650
  }), list?.length === 0 && /* @__PURE__ */ React.createElement("div", {
2741
3651
  className: "tcr-muted tcr-pad"
2742
3652
  }, t("noRuns")), list && list.length > 0 && /* @__PURE__ */ React.createElement("div", {
@@ -2752,16 +3662,19 @@ function TaskRow({
2752
3662
  client,
2753
3663
  task,
2754
3664
  now,
3665
+ grouped,
3666
+ showDir,
2755
3667
  onEdit,
2756
3668
  onSwitch
2757
3669
  }) {
2758
3670
  const [open, setOpen] = React.useState(false);
2759
3671
  const [menu, openMenu] = pi.ui.useContextMenu();
2760
3672
  const More = icon("Ellipsis");
2761
- const Mark = icon(task.schedule.kind === "once" ? "Clock" : "AlarmClock");
3673
+ const Mark = icon(task.schedule.kind === "once" ? "Clock" : ScheduleUtil.isEvent(task.schedule) ? "Zap" : "AlarmClock");
2762
3674
  const running = task.lastStatus === "running";
2763
- 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");
3675
+ const state = stateOf(task, new Date(now), grouped);
2764
3676
  const tone = running ? "running" : !task.enabled ? "off" : task.lastStatus ?? "idle";
3677
+ const failed = TaskList.failed(task);
2765
3678
  const [switching, run] = useBusy(pi.ui);
2766
3679
  const remove = async () => {
2767
3680
  if (await pi.ui.confirm(t("confirmDelete", { name: task.name }), t("confirmDeleteMessage"), { confirmLabel: t("delete"), danger: true })) {
@@ -2777,6 +3690,7 @@ function TaskRow({
2777
3690
  ],
2778
3691
  [{ key: "delete", label: t("delete"), icon: icon("Trash2"), danger: true, run: () => void remove() }]
2779
3692
  ];
3693
+ const last = task.lastRunAt && ScheduleUtil.clock(new Date(task.lastRunAt), new Date(now));
2780
3694
  return /* @__PURE__ */ React.createElement("div", {
2781
3695
  className: `tcr-task${open ? " tcr-open" : ""}${task.enabled ? "" : " tcr-disabled"}`
2782
3696
  }, /* @__PURE__ */ React.createElement("div", {
@@ -2792,9 +3706,6 @@ function TaskRow({
2792
3706
  "aria-hidden": "true"
2793
3707
  }, /* @__PURE__ */ React.createElement(Mark, {
2794
3708
  size: 17
2795
- }), /* @__PURE__ */ React.createElement(Dot, {
2796
- status: task.lastStatus,
2797
- enabled: task.enabled || running
2798
3709
  })), /* @__PURE__ */ React.createElement("span", {
2799
3710
  className: "tcr-task-text"
2800
3711
  }, /* @__PURE__ */ React.createElement("span", {
@@ -2802,15 +3713,19 @@ function TaskRow({
2802
3713
  }, task.name), /* @__PURE__ */ React.createElement("span", {
2803
3714
  className: "tcr-task-meta"
2804
3715
  }, /* @__PURE__ */ React.createElement("span", {
2805
- className: "tcr-chip"
2806
- }, ScheduleUtil.describe(task.schedule, pi.ui.language, new Date(now))), /* @__PURE__ */ React.createElement("span", {
3716
+ className: "tcr-task-rule"
3717
+ }, ScheduleUtil.describe(task.schedule, pi.ui.language, new Date(now))), showDir && /* @__PURE__ */ React.createElement("span", {
2807
3718
  className: "tcr-task-dir",
2808
3719
  title: task.cwd
2809
3720
  }, basename(task.cwd)), /* @__PURE__ */ React.createElement("span", {
2810
- className: `tcr-task-next${running ? " tcr-pulse" : ""}`
2811
- }, state), task.lastRunAt && /* @__PURE__ */ React.createElement("span", {
2812
- className: "tcr-task-last"
2813
- }, t("lastRun", { time: ScheduleUtil.clock(new Date(task.lastRunAt), new Date(now)) })))), /* @__PURE__ */ React.createElement("span", {
3721
+ className: `tcr-task-next${running ? " tcr-pulse" : ""}${task.enabled && !running && task.nextRunAt ? " tcr-is-time" : ""}`
3722
+ }, state), last && /* @__PURE__ */ React.createElement("span", {
3723
+ className: `tcr-task-last${failed ? " tcr-is-error" : ""}`
3724
+ }, /* @__PURE__ */ React.createElement("span", {
3725
+ className: "tcr-last-full"
3726
+ }, t(failed ? "lastFailed" : "lastRun", { time: last })), /* @__PURE__ */ React.createElement("span", {
3727
+ className: "tcr-last-short"
3728
+ }, t(failed ? "lastFailed" : "lastRun", { time: "" }).trim())))), /* @__PURE__ */ React.createElement("span", {
2814
3729
  className: `tcr-task-state${running ? " tcr-pulse" : ""}`,
2815
3730
  title: task.nextRunAt ? t("nextAt", { time: ScheduleUtil.clock(new Date(task.nextRunAt)) }) : undefined
2816
3731
  }, state)), /* @__PURE__ */ React.createElement("label", {
@@ -2844,6 +3759,113 @@ function TaskRow({
2844
3759
  onEdit
2845
3760
  }), menu);
2846
3761
  }
3762
+
3763
+ // web-src/tasks-view.tsx
3764
+ function useMinute() {
3765
+ const [now, setNow] = React.useState(Date.now());
3766
+ React.useEffect(() => {
3767
+ const timer = setInterval(() => setNow(Date.now()), 30000);
3768
+ return () => clearInterval(timer);
3769
+ }, []);
3770
+ return now;
3771
+ }
3772
+ function Clock2() {
3773
+ return /* @__PURE__ */ React.createElement("svg", {
3774
+ className: "tcr-clock",
3775
+ viewBox: "0 0 120 120",
3776
+ "aria-hidden": "true"
3777
+ }, /* @__PURE__ */ React.createElement("circle", {
3778
+ cx: "60",
3779
+ cy: "60",
3780
+ r: "44",
3781
+ className: "tcr-clock-face"
3782
+ }), Array.from({ length: 12 }, (_, hour) => /* @__PURE__ */ React.createElement("line", {
3783
+ key: hour,
3784
+ x1: "60",
3785
+ y1: "22",
3786
+ x2: "60",
3787
+ y2: hour % 3 === 0 ? 29 : 26,
3788
+ className: "tcr-clock-tick",
3789
+ transform: `rotate(${hour * 30} 60 60)`
3790
+ })), /* @__PURE__ */ React.createElement("line", {
3791
+ x1: "60",
3792
+ y1: "60",
3793
+ x2: "60",
3794
+ y2: "38",
3795
+ className: "tcr-clock-hour"
3796
+ }), /* @__PURE__ */ React.createElement("line", {
3797
+ x1: "60",
3798
+ y1: "60",
3799
+ x2: "60",
3800
+ y2: "28",
3801
+ className: "tcr-clock-hand"
3802
+ }), /* @__PURE__ */ React.createElement("circle", {
3803
+ cx: "60",
3804
+ cy: "60",
3805
+ r: "3.5",
3806
+ className: "tcr-clock-pin"
3807
+ }));
3808
+ }
3809
+ var EXAMPLES = [
3810
+ { text: "example1", editing: { repeat: "days", time: "09:00" }, rule: "0 9 * * *", picture: "commits" },
3811
+ { text: "example2", editing: { repeat: "every" }, rule: "30m", picture: "checks" },
3812
+ { text: "example3", editing: { repeat: "days", days: FormUtil.WEEKDAYS, time: "18:00" }, rule: "0 18 * * 1-5", picture: "report" }
3813
+ ];
3814
+ function Empty({ onPick }) {
3815
+ const PictureCards = pi.ui.PictureCards;
3816
+ const cards = EXAMPLES.map((example) => {
3817
+ const schedule = example.editing.repeat === "every" ? { kind: "interval", every: example.rule } : { kind: "cron", expression: example.rule };
3818
+ return {
3819
+ key: example.text,
3820
+ picture: /* @__PURE__ */ React.createElement(ExampleArt, {
3821
+ picture: example.picture
3822
+ }),
3823
+ label: t(example.text),
3824
+ hint: ScheduleUtil.describe(schedule, pi.ui.language),
3825
+ onPick: () => onPick({ ...example.editing, prompt: t(example.text) })
3826
+ };
3827
+ });
3828
+ return /* @__PURE__ */ React.createElement("div", {
3829
+ className: "tcr-empty"
3830
+ }, /* @__PURE__ */ React.createElement(Clock2, null), /* @__PURE__ */ React.createElement("div", {
3831
+ className: "tcr-empty-title"
3832
+ }, t("emptyTitle")), /* @__PURE__ */ React.createElement("div", {
3833
+ className: "tcr-empty-hint"
3834
+ }, t("emptyHint")), /* @__PURE__ */ React.createElement("div", {
3835
+ className: "tcr-examples"
3836
+ }, /* @__PURE__ */ React.createElement(PictureCards, {
3837
+ cards
3838
+ })));
3839
+ }
3840
+ var FILTERS = [
3841
+ ["on", "filterOn"],
3842
+ ["failed", "filterFailed"],
3843
+ ["off", "filterOff"]
3844
+ ];
3845
+ var GROUP_WORDS = {
3846
+ running: "groupRunning",
3847
+ today: "groupToday",
3848
+ tomorrow: "groupTomorrow",
3849
+ week: "groupWeek",
3850
+ later: "groupLater",
3851
+ event: "groupEvent",
3852
+ done: "groupDone"
3853
+ };
3854
+ function Filters({ value, counts, onChange }) {
3855
+ return /* @__PURE__ */ React.createElement("div", {
3856
+ className: "ta-segmented tcr-filters",
3857
+ role: "tablist"
3858
+ }, FILTERS.filter(([filter]) => filter === "on" || filter === value || counts[filter] > 0).map(([filter, word]) => /* @__PURE__ */ React.createElement("button", {
3859
+ key: filter,
3860
+ type: "button",
3861
+ role: "tab",
3862
+ "aria-selected": value === filter,
3863
+ className: `${value === filter ? "ta-on " : ""}tcr-filter-${filter}`,
3864
+ onClick: () => onChange(filter)
3865
+ }, t(word), /* @__PURE__ */ React.createElement("span", {
3866
+ className: "tcr-filter-count"
3867
+ }, counts[filter]))));
3868
+ }
2847
3869
  function TasksHead({ client }) {
2848
3870
  const Plus = icon("Plus");
2849
3871
  return /* @__PURE__ */ React.createElement("div", {
@@ -2861,63 +3883,59 @@ function TasksHead({ client }) {
2861
3883
  })));
2862
3884
  }
2863
3885
  function TasksPage({ client }) {
3886
+ const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
2864
3887
  const { tasks, loaded } = useClient(client);
2865
3888
  const now = useMinute();
2866
3889
  const [editing, setEditing] = React.useState();
3890
+ const [filter, setFilter] = React.useState("on");
2867
3891
  React.useEffect(() => client.onAskNew(() => setEditing({})), [client]);
2868
- const running = tasks.filter((task) => task.lastStatus === "running").length;
2869
- const sorted = [...tasks].sort((a, b) => Number(b.enabled) - Number(a.enabled) || (a.nextRunAt ?? "~").localeCompare(b.nextRunAt ?? "~"));
2870
3892
  const [stay, setStay] = React.useState(new Set);
2871
- const [offOpen, setOffOpen] = React.useState(false);
2872
- const [listed, off] = TaskUtil.split(sorted, stay);
2873
3893
  const edit = React.useCallback((task) => setEditing({ task }), []);
2874
3894
  const onSwitch = React.useCallback((task, on) => {
2875
3895
  if (!on) {
2876
3896
  setStay((ids) => new Set(ids).add(task.id));
2877
3897
  }
2878
3898
  }, []);
2879
- const Chevron = icon("ChevronRight");
2880
- const row = (task) => /* @__PURE__ */ React.createElement(TaskRow, {
3899
+ const counts = TaskList.counts(tasks, stay);
3900
+ const listed = TaskList.filter(tasks, filter, stay);
3901
+ const showDir = new Set(tasks.map((task) => task.cwd)).size > 1;
3902
+ const row = (task, grouped) => /* @__PURE__ */ React.createElement(TaskRow, {
2881
3903
  key: task.id,
2882
3904
  client,
2883
3905
  task,
2884
3906
  now,
3907
+ grouped,
3908
+ showDir,
2885
3909
  onEdit: edit,
2886
3910
  onSwitch
2887
3911
  });
3912
+ const Check = icon("CircleCheck");
2888
3913
  return /* @__PURE__ */ React.createElement("div", {
2889
3914
  className: "tcr-scroll"
2890
3915
  }, /* @__PURE__ */ React.createElement("div", {
2891
3916
  className: "tcr-page"
2892
- }, tasks.length > 0 && /* @__PURE__ */ React.createElement("div", {
2893
- className: "tcr-head"
2894
- }, /* @__PURE__ */ React.createElement("div", {
2895
- className: "tcr-stat"
2896
- }, t("count", { count: tasks.length }), running > 0 && /* @__PURE__ */ React.createElement("span", {
2897
- className: "tcr-pulse"
2898
- }, " · ", t("runningCount", { count: running })))), !loaded && /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
2899
- rows: 3
2900
- }), loaded && tasks.length === 0 && /* @__PURE__ */ React.createElement(Empty, {
3917
+ }, tasks.length > 0 && /* @__PURE__ */ React.createElement(Filters, {
3918
+ value: filter,
3919
+ counts,
3920
+ onChange: setFilter
3921
+ }), !loaded && /* @__PURE__ */ React.createElement(Loading, null), loaded && tasks.length === 0 && /* @__PURE__ */ React.createElement(Empty, {
2901
3922
  onPick: setEditing
2902
- }), /* @__PURE__ */ React.createElement("div", {
3923
+ }), loaded && tasks.length > 0 && listed.length === 0 && /* @__PURE__ */ React.createElement("div", {
3924
+ className: "tcr-none"
3925
+ }, /* @__PURE__ */ React.createElement(Check, {
3926
+ size: 18
3927
+ }), t(filter === "failed" ? "noneFailed" : filter === "off" ? "noneOff" : "noneOn")), filter === "on" ? TaskList.groups(listed, new Date(now)).map(({ group, tasks: grouped }) => /* @__PURE__ */ React.createElement("section", {
3928
+ key: group,
3929
+ className: "tcr-group"
3930
+ }, /* @__PURE__ */ React.createElement("div", {
3931
+ className: "tcr-group-title"
3932
+ }, t(GROUP_WORDS[group]), /* @__PURE__ */ React.createElement("span", {
3933
+ className: "tcr-group-count"
3934
+ }, grouped.length)), /* @__PURE__ */ React.createElement("div", {
2903
3935
  className: "tcr-list"
2904
- }, listed.map(row)), off.length > 0 && /* @__PURE__ */ React.createElement("section", {
2905
- className: `tcr-off-group${offOpen ? " tcr-open" : ""}`
2906
- }, /* @__PURE__ */ React.createElement("button", {
2907
- type: "button",
2908
- className: "tcr-fold",
2909
- "aria-expanded": offOpen,
2910
- onClick: () => setOffOpen(!offOpen)
2911
- }, /* @__PURE__ */ React.createElement("span", {
2912
- className: "tcr-chevron",
2913
- "aria-hidden": "true"
2914
- }, /* @__PURE__ */ React.createElement(Chevron, {
2915
- size: 14
2916
- })), t("offGroup"), /* @__PURE__ */ React.createElement("span", {
2917
- className: "tcr-count"
2918
- }, off.length)), offOpen && /* @__PURE__ */ React.createElement("div", {
3936
+ }, grouped.map((task) => row(task, group === "today" || group === "tomorrow"))))) : /* @__PURE__ */ React.createElement("div", {
2919
3937
  className: "tcr-list"
2920
- }, off.map(row)))), editing && /* @__PURE__ */ React.createElement(TaskEditor, {
3938
+ }, listed.map((task) => row(task, false)))), editing && /* @__PURE__ */ React.createElement(TaskEditor, {
2921
3939
  client,
2922
3940
  editing,
2923
3941
  onClose: () => setEditing(undefined)
@@ -2928,6 +3946,7 @@ function TasksPage({ client }) {
2928
3946
  var VERBS = {
2929
3947
  add: "toolAdd",
2930
3948
  update: "toolUpdate",
3949
+ preview: "toolPreview",
2931
3950
  list: "toolList",
2932
3951
  show: "toolShow",
2933
3952
  enable: "toolEnable",
@@ -2949,6 +3968,9 @@ var CronToolLine;
2949
3968
  return { verb, target: text(args.name) || text(args.prompt).split(`
2950
3969
  `)[0] };
2951
3970
  }
3971
+ if (action === "preview") {
3972
+ return { verb, target: text(args.when) };
3973
+ }
2952
3974
  return { verb, target: action === "list" || action === "clear" ? "" : text(args.name) || text(args.id) };
2953
3975
  }
2954
3976
  CronToolLine.renderCall = renderCall;
@@ -2975,7 +3997,7 @@ function activate(pi2) {
2975
3997
  client
2976
3998
  }),
2977
3999
  order: 70,
2978
- discover: true
4000
+ group: "work"
2979
4001
  });
2980
4002
  pi2.registerView("next", {
2981
4003
  title: () => t("cardTitle"),
@@ -2986,6 +4008,7 @@ function activate(pi2) {
2986
4008
  client
2987
4009
  })
2988
4010
  });
4011
+ pi2.registerChatIcon?.({ icon: (chat) => chat.group === NAME ? { icon: icon("AlarmClock"), folder: t("title") } : undefined });
2989
4012
  pi2.registerMessageRenderer(REPLY_TYPE, ReplyMessage);
2990
4013
  CronToolLine.register(pi2, (key) => t(key));
2991
4014
  const stopWatching = watchRuns();