agent-loft 0.2.61 → 0.2.63

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.61",
3
+ "version": "0.2.63",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -17,6 +17,7 @@ import {
17
17
  type SDKUserMessage,
18
18
  } from "@anthropic-ai/claude-agent-sdk";
19
19
  import { agentEnvironment } from "../../core/agent-env.js";
20
+ import { usageOf } from "../../core/usage.js";
20
21
  import { expertAppend, expertSystemPrompt, RICH_REPLY_LINES, searchLabel } from "../../core/expert-prompt.js";
21
22
  import { ACCESS_LEVELS, type ExpertAccess } from "../../core/experts.js";
22
23
  import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
@@ -313,6 +314,8 @@ export class ClaudeSession implements AgentSession {
313
314
  * 恢复 / 分叉来的会话第一轮不知道之前累计了多少,这一轮先不报费用
314
315
  */
315
316
  private costSoFar: number | undefined;
317
+ /** 上一轮的累计 Token;恢复 / 分叉时优先从已保存的会话用量建立起点。 */
318
+ private tokensSoFar: number | undefined;
316
319
  /** 任务清单(见 todos.ts)。只记主线的,子 agent 自己列的不算 */
317
320
  private todos = new TodoTracker();
318
321
 
@@ -322,6 +325,10 @@ export class ClaudeSession implements AgentSession {
322
325
  private readonly host: InteractionHost,
323
326
  ) {
324
327
  this.costSoFar = opts.resumeId ? undefined : 0;
328
+ const previousUsage = usageOf(opts.resumeId);
329
+ this.tokensSoFar = previousUsage
330
+ ? previousUsage.input + previousUsage.cacheRead + previousUsage.cacheWrite + previousUsage.output
331
+ : opts.resumeId ? undefined : 0;
325
332
  // 接着老会话说:之前列的任务后面可能接着改(TaskUpdate 只给编号),先读回来。
326
333
  // 读一个本地文件,比模型第一次调工具快得多
327
334
  if (opts.resumeId) void readTodos(opts.resumeId, opts.cwd).then((items) => this.todos.seed(items));
@@ -449,11 +456,12 @@ export class ClaudeSession implements AgentSession {
449
456
 
450
457
  if (message.type === "result") {
451
458
  const costUsd = this.turnCost(message.total_cost_usd);
452
- this.reportUsage(message.modelUsage);
459
+ const tokens = this.reportUsage(message.modelUsage);
453
460
  if (message.subtype === "success") {
454
461
  this.events.onResult({
455
462
  text: message.result,
456
463
  ...(costUsd !== undefined ? { costUsd } : {}),
464
+ ...(tokens !== undefined ? { tokens } : {}),
457
465
  durationMs: message.duration_ms,
458
466
  ...(this.lastAssistantUuid ? { anchor: this.lastAssistantUuid } : {}),
459
467
  });
@@ -477,7 +485,7 @@ export class ClaudeSession implements AgentSession {
477
485
  * 报这个会话到目前的累计用量。用 modelUsage 而不是 usage:usage 只有主循环这一轮的,
478
486
  * modelUsage 含子 agent、压缩等所有调用,而且是累计值(恢复的会话接着原来的总数算)
479
487
  */
480
- private reportUsage(modelUsage: Record<string, ModelUsage> | undefined): void {
488
+ private reportUsage(modelUsage: Record<string, ModelUsage> | undefined): number | undefined {
481
489
  const sum: TokenUsage = { input: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0, costUsd: 0 };
482
490
  for (const m of Object.values(modelUsage ?? {})) {
483
491
  sum.input += m.inputTokens || 0;
@@ -487,8 +495,14 @@ export class ClaudeSession implements AgentSession {
487
495
  sum.reasoning! += m.thinkingTokens || 0;
488
496
  sum.costUsd! += m.costUSD || 0;
489
497
  }
490
- // 崩溃时的 result 全是 0
491
- if (sum.input + sum.cacheRead + sum.cacheWrite + sum.output > 0) this.events.onUsage?.(sum, true);
498
+ const total = sum.input + sum.cacheRead + sum.cacheWrite + sum.output;
499
+ // 崩溃时的 result 全是 0,不覆盖上一轮的起点。
500
+ if (!(total > 0)) return undefined;
501
+ const prev = this.tokensSoFar;
502
+ this.tokensSoFar = total;
503
+ this.events.onUsage?.(sum, true);
504
+ // 没有历史起点或累计值倒退时,先建立起点,避免把旧用量当成本轮的。
505
+ return prev !== undefined && total >= prev ? total - prev : undefined;
492
506
  }
493
507
 
494
508
  /**
@@ -284,10 +284,11 @@ export class CodexSession implements AgentSession {
284
284
  /** 用户点过「本会话全部允许」。只在内存里,会话对象一换就重新逐条询问。 */
285
285
  private allowAll = false;
286
286
  private replyText = "";
287
- private lastTokens: number | undefined;
287
+ /** 本轮所有模型请求的用量,和会话汇总使用相同的输入 / 缓存 / 输出口径。 */
288
+ private turnTokens: number | undefined;
288
289
  /** 上次看到的 thread 累计 token 数:变了才说明有新的模型请求(同一次请求可能报好几遍) */
289
290
  private seenTotal: number | undefined;
290
- /** 这个对象里开始过轮次:恢复 thread 时补报的旧用量不算新的消耗 */
291
+ /** 当前轮次已开始:恢复 thread 时补报的旧用量不算新的消耗 */
291
292
  private turnSeen = false;
292
293
  /** 分叉已经真正完成(拿到并接管了新 thread)。失败了不算,重试还要接着分叉 */
293
294
  private forked = false;
@@ -360,6 +361,7 @@ export class CodexSession implements AgentSession {
360
361
  if (this.endedTurns.size > 50) this.endedTurns.delete(this.endedTurns.values().next().value!);
361
362
  }
362
363
  this.phase = "idle";
364
+ this.turnSeen = false;
363
365
  this.turnId = undefined;
364
366
  this.stopRequested = false;
365
367
  this.turnSeq += 1;
@@ -554,6 +556,8 @@ export class CodexSession implements AgentSession {
554
556
  private startTurn(input: UserInput): void {
555
557
  this.currentInput = input;
556
558
  this.replyText = "";
559
+ this.turnTokens = undefined;
560
+ this.turnSeen = false;
557
561
  this.phase = "starting";
558
562
  this.turnId = undefined;
559
563
  this.stopRequested = false;
@@ -854,7 +858,7 @@ export class CodexSession implements AgentSession {
854
858
  }
855
859
 
856
860
  case "thread/tokenUsage/updated": {
857
- // last 是最近一次模型请求的用量,total 是整条 thread 的累计;页脚显示最近一次的
861
+ // last 是最近一次模型请求的用量,total 是整条 thread 的累计;去重后累加到本轮页脚和会话汇总
858
862
  const usage = (params as { tokenUsage?: { total?: TokenBreakdown; last?: TokenBreakdown; modelContextWindow?: number | null } })
859
863
  .tokenUsage;
860
864
  const total = usage?.total?.totalTokens;
@@ -863,21 +867,22 @@ export class CodexSession implements AgentSession {
863
867
  // OpenAI 的 inputTokens 含命中缓存的部分,拆出来
864
868
  const cached = l.cachedInputTokens ?? 0;
865
869
  const written = l.cacheWriteInputTokens ?? 0;
866
- this.events.onUsage?.({
870
+ const delta = {
867
871
  input: Math.max(0, (l.inputTokens ?? 0) - cached - written),
868
872
  cacheRead: cached,
869
873
  cacheWrite: written,
870
874
  output: l.outputTokens ?? 0,
871
875
  reasoning: l.reasoningOutputTokens ?? 0,
872
- });
876
+ };
877
+ this.turnTokens = (this.turnTokens ?? 0) + delta.input + delta.cacheRead + delta.cacheWrite + delta.output;
878
+ this.events.onUsage?.(delta);
873
879
  }
874
880
  if (typeof total === "number") this.seenTotal = total;
875
- const turnTokens = usage?.last?.totalTokens;
876
- if (typeof turnTokens === "number") this.lastTokens = turnTokens;
881
+ const requestTokens = usage?.last?.totalTokens;
877
882
  // 最近一次请求的用量 ≈ 当前上下文大小(Codex 自己的「剩余上下文」也是这么算的)
878
883
  const window = usage?.modelContextWindow;
879
- if (typeof turnTokens === "number" && window) {
880
- this.events.onContext?.({ used: turnTokens, window, percent: Math.round((turnTokens / window) * 100) });
884
+ if (typeof requestTokens === "number" && window) {
885
+ this.events.onContext?.({ used: requestTokens, window, percent: Math.round((requestTokens / window) * 100) });
881
886
  }
882
887
  return;
883
888
  }
@@ -902,7 +907,7 @@ export class CodexSession implements AgentSession {
902
907
  this.events.onResult({
903
908
  text,
904
909
  durationMs: turn.durationMs ?? 0,
905
- ...(this.lastTokens !== undefined ? { tokens: this.lastTokens } : {}),
910
+ ...(this.turnTokens !== undefined ? { tokens: this.turnTokens } : {}),
906
911
  ...(turn.id ? { anchor: turn.id } : {}),
907
912
  });
908
913
  }
@@ -228,7 +228,7 @@ export function describeSchedule(s: TaskSchedule): string {
228
228
  case "weekdays":
229
229
  return `工作日 ${s.time}`;
230
230
  case "weekly":
231
- return s.days.length === 7 ? `每天 ${s.time}` : `每周${s.days.map((d) => WEEK[d]).join("、")} ${s.time}`;
231
+ return s.days.length === 7 ? `每天 ${s.time}` : `每周${[...s.days].sort((a, b) => (a || 7) - (b || 7)).map((d) => WEEK[d]).join("、")} ${s.time}`;
232
232
  case "monthly":
233
233
  return `每月 ${s.day} 日 ${s.time}`;
234
234
  case "hourly":
package/web/css/base.css CHANGED
@@ -192,8 +192,12 @@ select.input {
192
192
  .input:focus,
193
193
  .field input:focus,
194
194
  .field select:focus,
195
- .field textarea:focus {
196
- border-color: var(--accent);
195
+ .field textarea:focus,
196
+ .settings-page input:not([type="checkbox"]):not([type="radio"]):focus,
197
+ .settings-page select:focus,
198
+ .settings-page textarea:focus {
199
+ border-color: var(--fg-soft);
200
+ outline: none;
197
201
  }
198
202
 
199
203
  .btn {
@@ -7,6 +7,7 @@
7
7
  position: absolute;
8
8
  inset: 0 auto 0 0;
9
9
  z-index: 30;
10
+ background: var(--bg);
10
11
  transform: translateX(-100%);
11
12
  transition: transform 0.2s ease;
12
13
  width: min(84vw, 320px);
@@ -70,8 +70,8 @@
70
70
  }
71
71
 
72
72
  .rename-input:focus {
73
- border-color: var(--accent);
74
- box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
73
+ border-color: var(--fg-soft);
74
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 10%, transparent);
75
75
  }
76
76
 
77
77
  .dialog-foot {
@@ -336,7 +336,7 @@ button.list-item:hover {
336
336
  }
337
337
 
338
338
  .dir-manual:focus {
339
- border-color: var(--accent);
339
+ border-color: var(--fg-soft);
340
340
  }
341
341
 
342
342
  .dir-picker .modal-foot .muted {
package/web/css/tasks.css CHANGED
@@ -351,13 +351,7 @@ button.task-run:hover {
351
351
  gap: 12px;
352
352
  }
353
353
 
354
- /* 频率:上面选种类,下面填具体时间 */
355
- .task-freq-row {
356
- display: flex;
357
- flex-direction: column;
358
- gap: 8px;
359
- }
360
-
354
+ /* 执行时间:选择星期和当天的时间 */
361
355
  .task-freq {
362
356
  display: flex;
363
357
  flex-wrap: wrap;
@@ -389,23 +383,83 @@ button.task-run:hover {
389
383
  color: var(--fg-soft);
390
384
  }
391
385
 
392
- .day-chips {
386
+ .task-weekly-controls {
387
+ width: 100%;
388
+ min-width: 0;
389
+ padding: 14px;
390
+ border: 1px solid var(--border);
391
+ border-radius: 12px;
392
+ background: var(--bg-side);
393
+ }
394
+
395
+ .task-weekly-heading,
396
+ .task-clock-row {
393
397
  display: flex;
394
- gap: 4px;
398
+ align-items: center;
399
+ justify-content: space-between;
400
+ gap: 12px;
401
+ color: var(--fg-soft);
402
+ font-size: 13px;
395
403
  }
396
404
 
397
- .day-chip {
398
- width: 34px;
399
- height: 34px;
400
- border-radius: 50%;
405
+ .task-weekly-hint {
406
+ color: var(--fg-faint);
407
+ font-size: 12px;
408
+ }
409
+
410
+ .task-weekdays {
411
+ display: grid;
412
+ grid-template-columns: repeat(7, minmax(0, 1fr));
413
+ gap: 6px;
414
+ margin-top: 10px;
415
+ }
416
+
417
+ .task-weekday {
418
+ display: flex;
419
+ align-items: center;
420
+ justify-content: center;
421
+ min-width: 0;
422
+ height: 40px;
423
+ padding: 0;
424
+ border-radius: 8px;
401
425
  border: 1px solid var(--border);
426
+ background: var(--bg-input);
427
+ color: var(--fg-soft);
402
428
  font-size: 13px;
429
+ font-weight: 500;
430
+ line-height: 1;
431
+ white-space: nowrap;
403
432
  }
404
433
 
405
- .day-chip.on {
406
- background: var(--accent);
407
- border-color: var(--accent);
408
- color: var(--accent-fg);
434
+ .task-weekday:hover {
435
+ border-color: var(--fg-faint);
436
+ }
437
+
438
+ .task-weekday[aria-pressed="true"] {
439
+ background: var(--fg);
440
+ border-color: var(--fg);
441
+ color: var(--bg);
442
+ }
443
+
444
+ .task-weekday:focus-visible {
445
+ outline: 2px solid var(--fg);
446
+ outline-offset: 2px;
447
+ }
448
+
449
+ .task-clock-row {
450
+ margin-top: 14px;
451
+ padding-top: 12px;
452
+ border-top: 1px solid var(--border);
453
+ }
454
+
455
+ .field .task-clock-row input[type="time"] {
456
+ flex: 0 0 132px;
457
+ width: 132px;
458
+ min-width: 0;
459
+ height: 40px;
460
+ padding: 0 10px;
461
+ font-size: 15px;
462
+ font-variant-numeric: tabular-nums;
409
463
  }
410
464
 
411
465
  .task-static {
package/web/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, interactive-widget=resizes-content" />
6
6
  <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
7
- <meta name="theme-color" content="#1f1f1f" media="(prefers-color-scheme: dark)" />
7
+ <meta name="theme-color" content="#212121" media="(prefers-color-scheme: dark)" />
8
8
  <meta name="apple-mobile-web-app-capable" content="yes" />
9
9
  <meta name="apple-mobile-web-app-status-bar-style" content="default" />
10
10
  <meta name="apple-mobile-web-app-title" content="Agent Loft" />
@@ -15,25 +15,25 @@
15
15
  <link rel="stylesheet" href="/vendor/hljs-light.css" media="(prefers-color-scheme: light)" />
16
16
  <link rel="stylesheet" href="/vendor/hljs-dark.css" media="(prefers-color-scheme: dark)" />
17
17
  <!-- 顺序就是层叠顺序,不要随意调换 -->
18
- <link rel="stylesheet" href="/css/base.css" />
18
+ <link rel="stylesheet" href="/css/base.css?v=2" />
19
19
  <link rel="stylesheet" href="/css/sidebar.css" />
20
20
  <link rel="stylesheet" href="/css/topbar.css" />
21
21
  <link rel="stylesheet" href="/css/messages.css" />
22
22
  <link rel="stylesheet" href="/css/loader.css" />
23
23
  <link rel="stylesheet" href="/css/composer.css" />
24
- <link rel="stylesheet" href="/css/overlay.css" />
24
+ <link rel="stylesheet" href="/css/overlay.css?v=2" />
25
25
  <link rel="stylesheet" href="/css/search.css" />
26
26
  <link rel="stylesheet" href="/css/settings.css" />
27
27
  <link rel="stylesheet" href="/css/schedule.css" />
28
28
  <link rel="stylesheet" href="/css/todos.css" />
29
- <link rel="stylesheet" href="/css/tasks.css" />
29
+ <link rel="stylesheet" href="/css/tasks.css?v=3" />
30
30
  <link rel="stylesheet" href="/css/library.css" />
31
31
  <link rel="stylesheet" href="/css/skills.css" />
32
32
  <link rel="stylesheet" href="/css/experts.css" />
33
33
  <link rel="stylesheet" href="/css/terminal.css" />
34
34
  <link rel="stylesheet" href="/css/remote.css" />
35
35
  <link rel="stylesheet" href="/css/servers.css" />
36
- <link rel="stylesheet" href="/css/mobile.css" />
36
+ <link rel="stylesheet" href="/css/mobile.css?v=2" />
37
37
  </head>
38
38
  <body>
39
39
  <div id="app"><div class="boot"><span class="loft-loader xl" role="img" aria-label="加载中"><svg viewBox="96 56 320 388" aria-hidden="true"><defs><linearGradient id="boot-g" gradientUnits="userSpaceOnUse" x1="104" y1="104" x2="408" y2="408"><stop offset="0" stop-color="#3b82f6"/><stop offset="1" stop-color="#06b6d4"/></linearGradient></defs><path class="ll-shadow" d="M256 296L404 364L256 432L108 364Z" fill="url(#boot-g)"/><path class="ll-plate" d="M256 252L404 320L256 388L108 320Z" fill="url(#boot-g)"/><path class="ll-star ll-l" d="M152 186C158.46 217.54 158.46 217.54 190 224C158.46 230.46 158.46 230.46 152 262C145.54 230.46 145.54 230.46 114 224C145.54 217.54 145.54 217.54 152 186Z" fill="url(#boot-g)"/><path class="ll-star ll-c" d="M256 82C268.92 145.08 268.92 145.08 332 158C268.92 170.92 268.92 170.92 256 234C243.08 170.92 243.08 170.92 180 158C243.08 145.08 243.08 145.08 256 82Z" fill="url(#boot-g)"/><path class="ll-star ll-r" d="M360 186C366.46 217.54 366.46 217.54 398 224C366.46 230.46 366.46 230.46 360 262C353.54 230.46 353.54 230.46 322 224C353.54 217.54 353.54 217.54 360 186Z" fill="url(#boot-g)"/></svg></span></div></div>
@@ -8,23 +8,26 @@ import { field, saveButton } from "./common.js";
8
8
 
9
9
  // ---------- 记忆(每个人自己的) ----------
10
10
 
11
- export async function memoryTab(panel) {
11
+ export async function memoryTab(panel, refresh = false) {
12
12
  const box = h("div", { class: "section" }, h("h4", {}, "记忆"), h("span", { class: "spinner" }));
13
- fill(panel, box);
13
+ // 更新时保留旧内容,避免加载占位让页面变短、滚动位置被浏览器压回顶部。
14
+ if (!refresh) fill(panel, box);
14
15
  let mem;
15
16
  try {
16
17
  mem = await api("/api/account/memory");
17
18
  } catch (err) {
18
- fill(box, h("h4", {}, "记忆"), h("div", { class: "error-text" }, err.message));
19
+ if (refresh) toast(err.message);
20
+ else fill(box, h("h4", {}, "记忆"), h("div", { class: "error-text" }, err.message));
19
21
  return;
20
22
  }
21
- const reload = () => void memoryTab(panel);
23
+ const reload = () => memoryTab(panel, true);
22
24
  const run = (btn, fn) => async () => {
23
25
  btn.disabled = true;
24
26
  try {
25
- if ((await fn()) !== false) reload();
27
+ if ((await fn()) !== false) await reload();
26
28
  } catch (err) {
27
29
  toast(err.message);
30
+ } finally {
28
31
  btn.disabled = false;
29
32
  }
30
33
  };
@@ -116,6 +119,9 @@ export async function memoryTab(panel) {
116
119
  toast("已清空");
117
120
  });
118
121
 
122
+ // 数据都已就绪再替换;保留用户在等待接口期间滚动到的位置。
123
+ const scroller = panel.closest(".settings-body");
124
+ const scrollTop = scroller?.scrollTop ?? 0;
119
125
  fill(
120
126
  panel,
121
127
  h(
@@ -161,6 +167,7 @@ export async function memoryTab(panel) {
161
167
  h("div", { class: "row" }, clearBtn),
162
168
  ),
163
169
  );
170
+ if (scroller) scroller.scrollTop = scrollTop;
164
171
  }
165
172
 
166
173
  /** 记忆页里的「整理记忆」:什么时候整理、用哪个 agent 的哪个模型、现在整理、上次的结果 */
@@ -288,11 +288,12 @@ export function openTaskForm(task, preset) {
288
288
 
289
289
  // ---- 频率 ----
290
290
  const sch = { kind: "daily", time: "09:00", days: [1], day: 1, every: 2, minute: 0, expr: "0 9 * * *", at: Date.now() + 3600_000, ...(src.schedule ?? {}) };
291
- if (sch.kind === "weekdays" || sch.kind === "daily") sch.days = sch.days ?? [1];
291
+ if (sch.kind === "daily") sch.days = [...WEEK_ORDER];
292
+ else if (sch.kind === "weekdays") sch.days = [1, 2, 3, 4, 5];
292
293
  const freq = h("select", {}, FREQS.map(([v, label]) => h("option", { value: v, selected: v === sch.kind }, label)));
293
294
  const freqBox = h("div", { class: "task-freq" });
294
295
  const timeInput = () => {
295
- const el = h("input", { type: "time", value: sch.time, required: true });
296
+ const el = h("input", { type: "time", value: sch.time, required: true, "aria-label": "执行时刻" });
296
297
  el.oninput = () => (sch.time = el.value);
297
298
  return el;
298
299
  };
@@ -303,23 +304,28 @@ export function openTaskForm(task, preset) {
303
304
  const at = h("input", { type: "datetime-local", value: toLocalInput(sch.at) });
304
305
  at.oninput = () => (sch.at = new Date(at.value).getTime());
305
306
  parts.push(at);
306
- } else if (sch.kind === "daily" || sch.kind === "weekdays") {
307
- parts.push(timeInput());
308
- } else if (sch.kind === "weekly") {
307
+ } else if (["daily", "weekdays", "weekly"].includes(sch.kind)) {
309
308
  parts.push(
310
309
  h(
311
310
  "div",
312
- { class: "day-chips" },
313
- WEEK_ORDER.map((d) => {
314
- const b = h("button", { type: "button", class: `day-chip${sch.days.includes(d) ? " on" : ""}` }, WEEK_NAME[d]);
315
- b.onclick = () => {
316
- sch.days = sch.days.includes(d) ? sch.days.filter((x) => x !== d) : [...sch.days, d];
317
- b.classList.toggle("on", sch.days.includes(d));
318
- };
319
- return b;
320
- }),
311
+ { class: "task-weekly-controls" },
312
+ h("div", { class: "task-weekly-heading" }, h("span", {}, "重复日期"), h("span", { class: "task-weekly-hint" }, "可多选")),
313
+ h(
314
+ "div",
315
+ { class: "task-weekdays", role: "group", "aria-label": "执行星期(可多选)" },
316
+ WEEK_ORDER.map((d) => {
317
+ const b = h("button", { type: "button", class: "task-weekday", "aria-pressed": String(sch.days.includes(d)) }, `周${WEEK_NAME[d]}`);
318
+ b.onclick = () => {
319
+ sch.days = sch.days.includes(d) ? sch.days.filter((x) => x !== d) : [...sch.days, d];
320
+ // 改了预设的星期,就按自选的每周计划保存。
321
+ sch.kind = freq.value = "weekly";
322
+ b.setAttribute("aria-pressed", String(sch.days.includes(d)));
323
+ };
324
+ return b;
325
+ }),
326
+ ),
327
+ h("label", { class: "task-clock-row" }, h("span", {}, "执行时刻"), timeInput()),
321
328
  ),
322
- timeInput(),
323
329
  );
324
330
  } else if (sch.kind === "monthly") {
325
331
  const day = h("input", { type: "number", min: "1", max: "31", value: String(sch.day), class: "narrow" });
@@ -338,7 +344,11 @@ export function openTaskForm(task, preset) {
338
344
  }
339
345
  fill(freqBox, parts);
340
346
  };
341
- freq.onchange = renderFreq;
347
+ freq.onchange = () => {
348
+ if (freq.value === "daily") sch.days = [...WEEK_ORDER];
349
+ else if (freq.value === "weekdays") sch.days = [1, 2, 3, 4, 5];
350
+ renderFreq();
351
+ };
342
352
  renderFreq();
343
353
  const freqHint = `按服务端时区(${T.tz || "本地时间"})。两次运行至少隔 15 分钟。`;
344
354
 
@@ -401,7 +411,8 @@ export function openTaskForm(task, preset) {
401
411
  { class: "modal-body task-form" },
402
412
  field("名称", title),
403
413
  field("要做的事", prompt, "需要对比的写清楚怎么判断,比如「和上次的结果比」「版本号比当前的新才算更新」。"),
404
- field("频率", h("div", { class: "task-freq-row" }, freq, freqBox), freqHint),
414
+ field("频率", freq),
415
+ field("执行时间", freqBox, freqHint),
405
416
  field("提醒", notify),
406
417
  target ? field("结果发到", target) : field("结果发到", h("div", { class: "task-static" }, task?.convKey ? `专用对话「${task.convTitle || "对话"}」` : "专用对话(第一次运行时新建,之后都发到这条)")),
407
418
  dedicatedBox,
@@ -425,6 +436,7 @@ export function openTaskForm(task, preset) {
425
436
  ? { kind: "hourly", every: sch.every, minute: sch.minute }
426
437
  : { kind: "cron", expr: sch.expr };
427
438
  if (schedule.kind === "once" && !(schedule.at > Date.now())) return toast("运行时间要在现在之后");
439
+ if (schedule.kind === "weekly" && !schedule.days.length) return toast("至少选择一个执行星期");
428
440
  const dedicated = !target || target.value === "dedicated";
429
441
  if (dedicated && !expert.value) return toast("选一个专家");
430
442
  const payload = {