@xiangyixie/dsh-superagent 0.14.9 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Superagent 专属空间</title>
6
+ <title>Superagent 控制台</title>
7
7
  <style>
8
8
  :root {
9
9
  color-scheme: dark;
@@ -627,6 +627,115 @@
627
627
  .step.failed .sdot { background: var(--red); }
628
628
  .lane-progress-text { margin-top: 5px; color: var(--faint); font-size: 10.5px; }
629
629
 
630
+ /* ---- schedule rail: one square card per conversation, steps on tap ---- */
631
+ .sched-rail {
632
+ position: fixed; top: 58px; right: 0; bottom: 0; z-index: 19;
633
+ width: 320px; display: flex; flex-direction: column;
634
+ border-left: 1px solid var(--line); background: #0d1317;
635
+ box-shadow: -18px 0 50px rgba(0, 0, 0, .32);
636
+ transition: transform .18s ease-out;
637
+ }
638
+ .rail-toggle {
639
+ position: absolute; left: 0; top: 10px; z-index: 2;
640
+ width: 27px; height: 27px; padding: 0;
641
+ border: 1px solid var(--line); border-left: 0; border-radius: 0 7px 7px 0;
642
+ background: #162027; color: var(--muted); font-size: 14px; line-height: 1;
643
+ }
644
+ .rail-toggle:hover { color: var(--text); background: #1c2831; }
645
+ .rail-strip { display: none; }
646
+ body.rail-collapsed .sched-rail { transform: translateX(calc(100% - 34px)); }
647
+ body.rail-collapsed .rail-main { visibility: hidden; }
648
+ body.rail-collapsed .rail-strip {
649
+ display: flex; flex-direction: column; align-items: center; gap: 8px;
650
+ height: 100%; padding: 46px 0 16px;
651
+ }
652
+ .rail-strip-text {
653
+ writing-mode: vertical-rl; letter-spacing: .18em;
654
+ color: var(--muted); font-size: 10.5px;
655
+ }
656
+ .rail-count {
657
+ min-width: 18px; padding: 1px 4px; border-radius: 9px; text-align: center;
658
+ background: rgba(246, 193, 119, .16); color: var(--amber); font-size: 10px;
659
+ }
660
+ .rail-count[hidden] { display: none; }
661
+ .rail-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
662
+ .rail-head {
663
+ display: flex; align-items: baseline; gap: 8px; padding: 13px 14px 9px 20px;
664
+ border-bottom: 1px solid var(--line-soft);
665
+ }
666
+ .rail-head strong { font-size: 12px; }
667
+ .rail-facts { color: var(--faint); font-size: 10.5px; }
668
+ .rail-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 14px 20px 20px; }
669
+ .rail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
670
+ .rail-card {
671
+ position: relative; aspect-ratio: 1 / 1; min-width: 0; overflow: hidden;
672
+ display: flex; flex-direction: column; gap: 3px;
673
+ padding: 8px 9px; border: 1px solid var(--line-soft); border-radius: 10px;
674
+ background: #10171c; color: var(--text); text-align: left;
675
+ }
676
+ .rail-card:hover { border-color: #35464f; background: #131c22; }
677
+ .rail-card.current { border-color: #3a5a52; background: #101b1a; }
678
+ .rail-card.k-attention, .rail-card.k-approval { border-color: rgba(246, 193, 119, .42); background: rgba(246, 193, 119, .05); }
679
+ .rail-card.k-failed { border-color: rgba(255, 123, 114, .32); }
680
+ .rail-card.k-done { border-color: rgba(99, 214, 164, .22); }
681
+ .rail-card-top { display: flex; align-items: center; gap: 5px; min-width: 0; }
682
+ .rail-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: #3a4a55; }
683
+ .rail-dot.running { background: var(--amber); animation: blink 1.1s infinite; }
684
+ .rail-dot.attention, .rail-dot.approval { background: var(--amber); }
685
+ .rail-dot.done { background: var(--green); }
686
+ .rail-dot.failed { background: var(--red); }
687
+ .rail-state {
688
+ min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
689
+ color: var(--muted); font-size: 10px;
690
+ }
691
+ .rail-when { margin-left: auto; flex: none; color: var(--faint); font: 9.5px var(--mono); }
692
+ .rail-title {
693
+ display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
694
+ color: var(--text); font-size: 11.5px; line-height: 1.35; word-break: break-word;
695
+ }
696
+ .rail-now {
697
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
698
+ color: var(--amber); font-size: 9.5px;
699
+ }
700
+ .rail-now.idle { color: var(--faint); }
701
+ .rail-meta {
702
+ margin-top: auto; display: flex; flex-wrap: wrap; gap: 1px 6px;
703
+ color: var(--faint); font-size: 9.5px; line-height: 1.4;
704
+ }
705
+ .rail-meta b { color: var(--muted); font-weight: 600; }
706
+ .rail-empty { margin: 0; color: var(--faint); font-size: 11px; line-height: 1.6; }
707
+ .rail-back {
708
+ display: inline-flex; align-items: center; gap: 4px; margin: 0 0 9px; padding: 0;
709
+ border: 0; background: transparent; color: var(--muted); font-size: 11px;
710
+ }
711
+ .rail-back:hover { color: var(--text); }
712
+ .rail-detail-head { margin-bottom: 10px; }
713
+ .rail-detail-title {
714
+ margin: 0 0 4px; font-size: 12.5px; line-height: 1.4; word-break: break-word;
715
+ }
716
+ .rail-detail-facts { color: var(--faint); font-size: 10.5px; line-height: 1.55; }
717
+ .rail-run {
718
+ margin-bottom: 8px; padding: 8px 9px; border-radius: 9px;
719
+ border: 1px solid var(--line-soft); background: #0e1418;
720
+ }
721
+ .rail-run:last-child { margin-bottom: 0; }
722
+ .rail-run-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
723
+ .rail-run-goal {
724
+ flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
725
+ color: var(--muted); font-size: 11px;
726
+ }
727
+ .rail-elapsed { flex: none; color: var(--faint); font: 9.5px var(--mono); white-space: nowrap; }
728
+ .rail-steps { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
729
+ .rail-steps .step { font-size: 10.5px; }
730
+ .rail-step-text { min-width: 0; word-break: break-word; }
731
+ .rail-step-note { color: var(--faint); }
732
+ .rail-step-dur { flex: none; margin-left: auto; color: var(--faint); font: 9.5px var(--mono); white-space: nowrap; }
733
+ .rail-note { margin: 0 0 8px; color: var(--faint); font-size: 10.5px; }
734
+ /* Wide screens give the rail its own column; narrow ones overlay it below. */
735
+ @media (min-width: 721px) {
736
+ body.rail-open .stage { padding-right: 338px; }
737
+ }
738
+
630
739
  .summary {
631
740
  margin-top: 10px; padding: 10px 11px; border-radius: 10px;
632
741
  border: 1px solid rgba(99, 214, 164, .28); background: rgba(99, 214, 164, .05);
@@ -699,7 +808,12 @@
699
808
  .brand { min-width: 0; }
700
809
  .brand div span { display: none; }
701
810
  .hint { display: none; }
702
- .messages { padding: 16px 14px 22px; }
811
+ .messages { padding: 16px 14px 22px; }
812
+ /* The rail floats over the thread instead of squeezing it into a column. */
813
+ .sched-rail { width: min(320px, calc(100vw - 42px)); box-shadow: -26px 0 60px rgba(0, 0, 0, .55); }
814
+ .rail-head { padding-left: 16px; }
815
+ .rail-body { padding-left: 14px; }
816
+ .rail-grid { gap: 7px; }
703
817
  }
704
818
  </style>
705
819
  </head>
@@ -708,7 +822,7 @@
708
822
  <header class="topbar">
709
823
  <div class="brand">
710
824
  <div class="mark">S</div>
711
- <div><strong>Superagent</strong><span>专属空间</span></div>
825
+ <div><strong>Superagent</strong><span>控制台</span></div>
712
826
  </div>
713
827
  <div class="topbar-mid">
714
828
  <span id="modeBadge" class="badge"><span class="pulse"></span><span id="modeText">连接中</span></span>
@@ -735,14 +849,13 @@
735
849
  <div class="chat-head">
736
850
  <div>
737
851
  <h1>Superagent</h1>
738
- <p>说一句就行 · 自动拆成任务线并行推进 · 跑完在这一条对话里汇总</p>
852
+ <p>说一句要做什么;它自己决定一步做完还是拆开并行,跑完在这里汇总</p>
739
853
  </div>
740
854
  <div id="typing" class="typing" hidden><span></span><span></span><span></span><em id="typingText" style="font-style:normal;margin-left:3px">运行中</em></div>
741
855
  </div>
742
- <div id="messages" class="messages" aria-live="polite"></div>
743
- <form id="composer" class="composer" autocomplete="off">
856
+ <div id="messages" class="messages" aria-live="polite"></div> <form id="composer" class="composer" autocomplete="off">
744
857
  <div class="composer-box">
745
- <textarea id="input" rows="1" placeholder="直接说你想让它做什么…" disabled></textarea>
858
+ <textarea id="input" rows="1" placeholder="要做什么…" disabled></textarea>
746
859
  <div class="composer-bar">
747
860
  <span class="hint">Enter 发送 · Shift+Enter 换行</span>
748
861
  <button id="send" class="send" type="submit" aria-label="发送" disabled>↑</button>
@@ -787,7 +900,7 @@
787
900
  <h3>会话</h3>
788
901
  <div id="advSession" class="adv-kv"></div>
789
902
  <div class="adv-actions">
790
- <button id="wizardOpen" class="btn tiny" type="button">首次使用向导</button>
903
+ <button id="wizardOpen" class="btn tiny" type="button">配置向导</button>
791
904
  </div>
792
905
  </section>
793
906
  <section class="adv-sec">
@@ -813,22 +926,37 @@
813
926
  <div id="gate" class="gate" hidden>
814
927
  <form id="gateForm" class="gate-card">
815
928
  <div class="mark">S</div>
816
- <h1>连接 Superagent Console</h1>
817
- <p>从宿主状态目录的 <code>console.json</code> 读取一次性 token。控制台只监听 127.0.0.1,token 每次启动都会重新生成。</p>
818
- <label for="tokenInput">访问令牌</label>
929
+ <h1>连接 Superagent 控制台</h1>
930
+ <p>token 在宿主状态目录的 <code>console.json</code> 里,每次启动都会换。控制台只监听 127.0.0.1。</p>
931
+ <label for="tokenInput">token</label>
819
932
  <input id="tokenInput" type="password" autocomplete="off" spellcheck="false" placeholder="粘贴 token">
820
933
  <button type="submit">连接</button>
821
934
  <p id="gateError" class="error"></p>
822
935
  </form>
823
936
  </div>
824
937
 
825
- <div id="toasts" class="toasts" aria-live="polite"></div>
938
+ <div id="toasts" class="toasts" aria-live="polite"></div>
939
+
940
+ <aside id="schedRail" class="sched-rail" aria-label="会话调度">
941
+ <button id="railToggle" class="rail-toggle" type="button" aria-label="收起调度" title="收起调度">›</button>
942
+ <div class="rail-strip" aria-hidden="true">
943
+ <span class="rail-strip-text">调度</span>
944
+ <b id="railCount" class="rail-count">0</b>
945
+ </div>
946
+ <div class="rail-main">
947
+ <div class="rail-head">
948
+ <strong>会话</strong>
949
+ <span id="railFacts" class="rail-facts"></span>
950
+ </div>
951
+ <div id="railBody" class="rail-body"></div>
952
+ </div>
953
+ </aside>
826
954
 
827
955
  <dialog id="wizardDialog">
828
956
  <div class="wiz-head">
829
957
  <div>
830
- <span class="kicker">首次使用向导</span>
831
- <h2>用鼠标完成配置,并当场试跑</h2>
958
+ <span class="kicker">首次配置</span>
959
+ <h2>填好配置,当场试跑</h2>
832
960
  </div>
833
961
  <button id="wizardClose" type="button" aria-label="关闭">×</button>
834
962
  </div>
@@ -894,6 +1022,11 @@
894
1022
  const noticeCountEl = $('noticeCount')
895
1023
  const noticePanelEl = $('noticePanel')
896
1024
  const noticeListEl = $('noticeList')
1025
+ const railToggleEl = $('railToggle')
1026
+ const railBodyEl = $('railBody')
1027
+ const railFactsEl = $('railFacts')
1028
+ const railCountEl = $('railCount')
1029
+ const RAIL_KEY = 'dsh-superagent-rail-collapsed'
897
1030
 
898
1031
  // Upload rules mirror the server's: the page refuses early with a readable
899
1032
  // sentence, and the server refuses again because a page is not a gate.
@@ -932,6 +1065,11 @@
932
1065
  preset: null,
933
1066
  laneEls: new Map(),
934
1067
  runAnchors: new Map(),
1068
+ schedules: [],
1069
+ schedulesNote: null,
1070
+ schedulesBusy: false,
1071
+ railDetail: null,
1072
+ railSig: '',
935
1073
  attentionSeen: new Set(),
936
1074
  approvals: new Map(),
937
1075
  sessions: [],
@@ -999,7 +1137,7 @@
999
1137
 
1000
1138
  function statusText(status) {
1001
1139
  const map = {
1002
- queued: '排队中', planning: '规划中', running: '运行中', aggregating: '汇总中',
1140
+ queued: '排队中', planning: '拆步骤中', running: '运行中', aggregating: '汇总中',
1003
1141
  completed: '已完成', failed: '失败', cancelled: '已取消', interrupted: '已中断',
1004
1142
  blocked: '已阻塞',
1005
1143
  }
@@ -1063,8 +1201,8 @@
1063
1201
 
1064
1202
  function setSession(sessionId) {
1065
1203
  STATE.sessionId = sessionId
1066
- sessionLabelEl.textContent = sessionId ? `session ${shortId(sessionId)}` : 'no session'
1067
- sessionLabelEl.title = sessionId || 'Host Session id'
1204
+ sessionLabelEl.textContent = sessionId ? `session ${shortId(sessionId)}` : '没有会话'
1205
+ sessionLabelEl.title = sessionId || '宿主会话 id'
1068
1206
  }
1069
1207
 
1070
1208
  function scrollToEnd() {
@@ -1131,13 +1269,13 @@
1131
1269
  if (message.role === 'assistant') {
1132
1270
  const copy = el('button', '', '复制')
1133
1271
  copy.type = 'button'
1134
- copy.title = '复制这条回复的完整文本'
1272
+ copy.title = '复制这条回复的全文'
1135
1273
  copy.addEventListener('click', () => copyMessage(message, copy))
1136
1274
  actions.append(copy)
1137
1275
  } else {
1138
1276
  const edit = el('button', '', '编辑并重发')
1139
1277
  edit.type = 'button'
1140
- edit.title = '把这条原文放回输入框,改完再发送'
1278
+ edit.title = '把原文放回输入框,改完再发'
1141
1279
  edit.addEventListener('click', () => editMessage(message))
1142
1280
  actions.append(edit)
1143
1281
  }
@@ -1183,10 +1321,10 @@
1183
1321
  async function copyMessage(message, button) {
1184
1322
  const copied = await copyText(formatTextOf(message))
1185
1323
  if (!copied) {
1186
- pushToast('复制失败,可以手动选中文字。', 'err')
1324
+ pushToast('复制失败。手动选中文字再复制。', 'err')
1187
1325
  return
1188
1326
  }
1189
- pushToast('已复制这条回复。', 'ok')
1327
+ pushToast('已复制。', 'ok')
1190
1328
  button.textContent = '已复制'
1191
1329
  setTimeout(() => { button.textContent = '复制' }, 1600)
1192
1330
  }
@@ -1199,7 +1337,7 @@
1199
1337
  inputEl.dispatchEvent(new Event('input'))
1200
1338
  inputEl.focus()
1201
1339
  try { inputEl.setSelectionRange(text.length, text.length) } catch { /* not focusable yet */ }
1202
- pushToast('原文已放回输入框,改完点发送。', 'ok')
1340
+ pushToast('已放回输入框,改完点发送。', 'ok')
1203
1341
  }
1204
1342
 
1205
1343
  function summarizeArgs(value) {
@@ -1227,7 +1365,7 @@
1227
1365
  if (tool.done) {
1228
1366
  const details = el('details')
1229
1367
  details.append(el('summary', failed ? 'err-mark' : '', failed ? '失败原因' : '结果'))
1230
- details.append(el('pre', '', tool.result || (failed ? '工具没有返回错误文本。' : '')))
1368
+ details.append(el('pre', '', tool.result || (failed ? '工具没有给出错误说明。' : '')))
1231
1369
  chip.append(details)
1232
1370
  }
1233
1371
  return chip
@@ -1286,15 +1424,15 @@
1286
1424
  if (STATE.mode !== 'chat') {
1287
1425
  wrap.classList.add('unavailable')
1288
1426
  wrap.append(el('div', 'orb', '!'))
1289
- wrap.append(el('h1', '', '对话不可用'))
1290
- wrap.append(el('p', '', '这个宿主没有提供可对话的 Session。控制台不会画一个假聊天框。'))
1427
+ wrap.append(el('h1', '', '这里不能对话'))
1428
+ wrap.append(el('p', '', '宿主没有可用的会话,所以这里不能开始对话。'))
1291
1429
  if (STATE.capabilities?.reason) wrap.append(el('div', 'reason', STATE.capabilities.reason))
1292
1430
  messagesEl.append(wrap)
1293
1431
  return
1294
1432
  }
1295
1433
  wrap.append(el('div', 'orb', 'S'))
1296
- wrap.append(el('h1', '', '今天想推进什么?'))
1297
- wrap.append(el('p', '', '这里是 Superagent 的专属空间,和宿主的普通会话分开。直接说一句就行:它会自己判断是一步做完,还是拆成几条任务线并行推进;跑完在这一条对话里汇总,并把可以点开的产物放在这里。'))
1434
+ wrap.append(el('h1', '', '要做什么?'))
1435
+ wrap.append(el('p', '', '写下要做的事。它自己决定一步做完,还是拆成几条同时做;跑完在这里汇总,能点开的产物也放在这里。'))
1298
1436
  const examples = el('div', 'examples')
1299
1437
  const samples = [
1300
1438
  '把这周的项目进度整理成一页 HTML 报告',
@@ -1394,7 +1532,7 @@
1394
1532
  noticeCountEl.textContent = unread > 99 ? '99+' : String(unread)
1395
1533
  noticeOpenEl.classList.toggle('has-unread', unread > 0)
1396
1534
  noticeOpenEl.title = unread > 0 ? `${unread} 条没看过的提醒` : '提醒'
1397
- const base = 'Superagent 专属空间'
1535
+ const base = 'Superagent 控制台'
1398
1536
  document.title = unread > 0 ? `(${unread}) ${base}` : base
1399
1537
  if (!noticePanelEl.hidden) renderNoticeList()
1400
1538
  }
@@ -1402,7 +1540,7 @@
1402
1540
  function renderNoticeList() {
1403
1541
  noticeListEl.textContent = ''
1404
1542
  if (STATE.notices.length === 0) {
1405
- noticeListEl.append(el('div', 'notice-empty', '还没有提醒。任务跑完、没走通或等你批准时会出现在这里。'))
1543
+ noticeListEl.append(el('div', 'notice-empty', '没有提醒。任务跑完、失败或等你批准时会出现在这里。'))
1406
1544
  return
1407
1545
  }
1408
1546
  for (const notice of STATE.notices) {
@@ -1506,21 +1644,21 @@
1506
1644
  const list = Array.from(files || []).filter(Boolean)
1507
1645
  if (list.length === 0) return
1508
1646
  if (STATE.mode !== 'chat') {
1509
- pushToast('还没连上,等对话就绪再放文件。', 'err')
1647
+ pushToast('还没连上,等对话准备好再放文件。', 'err')
1510
1648
  return
1511
1649
  }
1512
1650
  for (const file of list) {
1513
1651
  const ext = uploadExtOf(file.name)
1514
1652
  if (!UPLOAD_EXTS.has(ext)) {
1515
- pushToast(`不能放 ${ext || '没有扩展名的'} 文件;可以放:${UPLOAD_HINT}。`, 'err')
1653
+ pushToast(`不能放 ${ext || '没有扩展名的'} 文件。可以放:${UPLOAD_HINT}。`, 'err')
1516
1654
  continue
1517
1655
  }
1518
1656
  if (file.size > UPLOAD_MAX) {
1519
- pushToast(`${file.name} 有 ${uploadSizeText(file.size)},超过 ${uploadSizeText(UPLOAD_MAX)} 的上限。`, 'err')
1657
+ pushToast(`${file.name} 有 ${uploadSizeText(file.size)},超过 ${uploadSizeText(UPLOAD_MAX)} 上限。`, 'err')
1520
1658
  continue
1521
1659
  }
1522
1660
  if (file.size === 0) {
1523
- pushToast(`${file.name} 是空文件,没有放进去。`, 'err')
1661
+ pushToast(`${file.name} 是空文件,没放进去。`, 'err')
1524
1662
  continue
1525
1663
  }
1526
1664
  try {
@@ -1530,7 +1668,7 @@
1530
1668
  body: { sessionId: STATE.sessionId, name: file.name, data: base64OfBytes(bytes) },
1531
1669
  })
1532
1670
  insertUploadPath(data.path)
1533
- pushToast(`已放进工作区:${data.name}(路径已写进消息)。`, 'ok')
1671
+ pushToast(`已放进工作区:${data.name}。路径写进了消息。`, 'ok')
1534
1672
  } catch (error) {
1535
1673
  const hint = error.hint ? `。${error.hint}` : ''
1536
1674
  pushToast(`放不进去:${messageOf(error)}${hint}`, 'err')
@@ -1596,11 +1734,345 @@
1596
1734
  }
1597
1735
  }
1598
1736
 
1737
+ // ---------- schedule rail ----------
1738
+ //
1739
+ // The right-hand rail is a projection of what the host already writes: its
1740
+ // own conversation list plus the run records on disk (status, each step's
1741
+ // startedAt/finishedAt/waitingOn, the run's maxParallel and queue). Nothing
1742
+ // here invents a second queue or recomputes progress.
1743
+
1744
+ function timeOf(value) {
1745
+ const ms = typeof value === 'number' ? value : Date.parse(value)
1746
+ return Number.isFinite(ms) ? ms : null
1747
+ }
1748
+
1749
+ /** The live session reads STATE.runs; every other card reads the host list. */
1750
+ function railRows(session) {
1751
+ const rows = session.sessionId === STATE.sessionId && STATE.runs.length > 0
1752
+ ? STATE.runs
1753
+ : Array.isArray(session.rows) ? session.rows : []
1754
+ return rows.slice(0, 8)
1755
+ }
1756
+
1757
+ function railApprovals(sessionId) {
1758
+ if (sessionId !== STATE.sessionId) return 0
1759
+ let count = 0
1760
+ for (const entry of STATE.approvals.values()) if (!entry.decided) count += 1
1761
+ return count
1762
+ }
1763
+
1764
+ function railFactsOf(session) {
1765
+ const rows = railRows(session)
1766
+ const steps = rows.flatMap(run => (Array.isArray(run.subtasks) ? run.subtasks : []))
1767
+ const active = rows.filter(run => !isTerminal(run.status) && run.status !== 'queued')
1768
+ const queued = rows.filter(run => run.status === 'queued')
1769
+ const running = steps.filter(step => step.status === 'running')
1770
+ const waiting = steps.filter(step => step.status === 'waiting')
1771
+ const cap = rows.reduce((best, run) => Math.max(best, Number(run.limits?.maxParallel) || 0), 0)
1772
+ const attention = rows.reduce((sum, run) => sum + (Array.isArray(run.attention) ? run.attention.length : 0), 0)
1773
+ const approvals = railApprovals(session.sessionId)
1774
+ const latest = rows.reduce((best, run) => {
1775
+ const at = timeOf(run.createdAt) ?? 0
1776
+ return at > best.at ? { at, run } : best
1777
+ }, { at: -1, run: null }).run
1778
+ return { rows, steps, active, queued, running, waiting, cap, attention, approvals, latest }
1779
+ }
1780
+
1781
+ /** Card state, in the order a person would want to know about it. */
1782
+ function railStatusOf(session, facts) {
1783
+ if (facts.approvals > 0) return { kind: 'approval', text: '等审批', dot: 'approval' }
1784
+ if (facts.attention > 0) return { kind: 'attention', text: '等你决定', dot: 'attention' }
1785
+ if (facts.active.length > 0) return { kind: 'running', text: '在跑', dot: 'running' }
1786
+ if (facts.queued.length > 0) return { kind: 'queued', text: '排队', dot: '' }
1787
+ if (session.running === true && facts.rows.length === 0) return { kind: 'running', text: '在跑', dot: 'running' }
1788
+ const latest = facts.latest
1789
+ if (latest) {
1790
+ if (latest.status === 'completed') return { kind: 'done', text: '完成', dot: 'done' }
1791
+ if (latest.status === 'cancelled') return { kind: 'failed', text: '已取消', dot: 'failed' }
1792
+ if (isTerminal(latest.status)) return { kind: 'failed', text: '失败', dot: 'failed' }
1793
+ }
1794
+ return { kind: 'idle', text: '空闲', dot: '' }
1795
+ }
1796
+
1797
+ function railTitleOf(session) {
1798
+ if (typeof session.title === 'string' && session.title) return session.title
1799
+ if (typeof session.first === 'string' && session.first) return session.first
1800
+ if (session.sessionId === STATE.sessionId) return '当前会话'
1801
+ const rows = Array.isArray(session.rows) ? session.rows : []
1802
+ if (session.blank && rows.length === 0) return '空会话'
1803
+ return shortId(session.sessionId) || '会话'
1804
+ }
1805
+
1806
+ function railFactsLine(facts) {
1807
+ const parts = [`${facts.rows.length} 条任务线`]
1808
+ if (facts.running.length > 0) parts.push(`并行 ${facts.running.length}${facts.cap > 0 ? `/${facts.cap}` : ''}`)
1809
+ if (facts.waiting.length > 0) parts.push(`等前一步 ${facts.waiting.length}`)
1810
+ if (facts.queued.length > 0) parts.push(`排队 ${facts.queued.length}`)
1811
+ return parts.join(' · ')
1812
+ }
1813
+
1814
+ /** One short sentence about the thing that needs attention right now. */
1815
+ function railNowOf(session, facts, status) {
1816
+ if (status.kind === 'approval') return `有 ${facts.approvals} 个工具调用等你批`
1817
+ if (status.kind === 'attention') return `有 ${facts.attention} 个问题等你回`
1818
+ if (facts.active.length > 0) {
1819
+ const tools = [...new Set(facts.active.flatMap(run => runningToolsOf(run)))]
1820
+ if (tools.length > 0) return `工具 ${tools.slice(0, 2).join('、')}`
1821
+ const step = facts.active[0].subtasks?.find(item => item.status === 'running')
1822
+ return step ? stepLabel(step) : currentAction(facts.active[0])
1823
+ }
1824
+ const queued = facts.queued[0]
1825
+ if (queued) {
1826
+ const queue = queued.queue || {}
1827
+ return queue.position ? `排第 ${queue.position}${queue.of ? ` / ${queue.of}` : ''}` : '排队,等前面的跑完'
1828
+ }
1829
+ if (facts.rows.length === 0) return session.running ? '这一轮刚开始' : '还没有任务线'
1830
+ if (status.kind === 'done') return '这一轮已结束'
1831
+ if (status.kind === 'failed') return '没走通,点开看步骤'
1832
+ return '没有在跑的'
1833
+ }
1834
+
1835
+ function stepTitleOf(run, key) {
1836
+ const hit = (Array.isArray(run.subtasks) ? run.subtasks : []).find(subtask => subtask.key === key)
1837
+ return hit ? stepLabel(hit) : String(key)
1838
+ }
1839
+
1840
+ function stepDuration(step) {
1841
+ const start = timeOf(step.startedAt)
1842
+ if (start === null) return ''
1843
+ const end = timeOf(step.finishedAt) ?? (step.status === 'running' ? Date.now() : null)
1844
+ if (end === null) return ''
1845
+ return formatClock(end - start)
1846
+ }
1847
+
1848
+ function railClock(run) {
1849
+ const node = el('span', 'rail-elapsed', laneElapsed(run))
1850
+ const start = timeOf(run.createdAt)
1851
+ if (start !== null) node.dataset.start = String(start)
1852
+ const finish = timeOf(run.finishedAt)
1853
+ if (finish !== null) node.dataset.finish = String(finish)
1854
+ return node
1855
+ }
1856
+
1857
+ function railStep(run, step) {
1858
+ const row = el('div', `step ${step.status || 'pending'}`)
1859
+ row.append(el('span', 'sdot'))
1860
+ const text = el('span', 'rail-step-text', stepLabel(step))
1861
+ const notes = []
1862
+ if (step.status === 'running' && step.tool) notes.push(`工具 ${step.tool}`)
1863
+ const waits = Array.isArray(step.waitingOn) ? step.waitingOn : []
1864
+ if (waits.length > 0) notes.push(`等「${waits.map(key => stepTitleOf(run, key)).join('」「')}」`)
1865
+ else if (step.status === 'waiting') notes.push('等前一步')
1866
+ if (step.status === 'skipped') notes.push('跳过')
1867
+ if (notes.length > 0) text.append(el('span', 'rail-step-note', ` · ${notes.join(' · ')}`))
1868
+ row.append(text)
1869
+ const duration = stepDuration(step)
1870
+ if (duration) row.append(el('span', 'rail-step-dur', duration))
1871
+ return row
1872
+ }
1873
+
1874
+ function railRun(run) {
1875
+ const box = el('div', 'rail-run')
1876
+ const head = el('div', 'rail-run-head')
1877
+ head.append(el('span', `status-pill ${statusClass(run.status)}`, laneStatusText(run)))
1878
+ const goal = el('span', 'rail-run-goal', run.goal || '这条任务线')
1879
+ goal.title = run.goal || ''
1880
+ head.append(goal)
1881
+ head.append(railClock(run))
1882
+ box.append(head)
1883
+
1884
+ const steps = Array.isArray(run.subtasks) ? run.subtasks : []
1885
+ if (steps.length === 0) {
1886
+ box.append(el('p', 'rail-note', run.status === 'queued'
1887
+ ? '等前面的任务线跑完再开始'
1888
+ : run.status === 'planning' ? '拆步骤中,还没有步骤时间' : '还没有步骤记录'))
1889
+ return box
1890
+ }
1891
+ const queue = run.queue || {}
1892
+ if (run.status === 'queued' && queue.position) {
1893
+ box.append(el('p', 'rail-note', `排队第 ${queue.position}${queue.of ? ` / ${queue.of}` : ''}`))
1894
+ }
1895
+ const list = el('div', 'rail-steps')
1896
+ for (const step of steps.slice(0, 12)) list.append(railStep(run, step))
1897
+ if (steps.length > 12) list.append(el('p', 'rail-note', `还有 ${steps.length - 12} 个步骤`))
1898
+ box.append(list)
1899
+ return box
1900
+ }
1901
+
1902
+ function railDetailBody(session) {
1903
+ const facts = railFactsOf(session)
1904
+ const status = railStatusOf(session, facts)
1905
+ const wrap = el('div', 'rail-detail')
1906
+ const back = el('button', 'rail-back', '← 全部会话')
1907
+ back.type = 'button'
1908
+ back.addEventListener('click', () => {
1909
+ STATE.railDetail = null
1910
+ renderRail()
1911
+ })
1912
+ wrap.append(back)
1913
+
1914
+ const head = el('div', 'rail-detail-head')
1915
+ head.append(el('div', 'rail-detail-title', railTitleOf(session)))
1916
+ head.append(el('div', 'rail-detail-facts', [
1917
+ status.text, railFactsLine(facts), `更新 ${timeLabel(session.updatedAt) || '—'}`,
1918
+ ].join(' · ')))
1919
+ wrap.append(head)
1920
+
1921
+ if (facts.rows.length === 0) {
1922
+ wrap.append(el('p', 'rail-empty', session.running
1923
+ ? '这一轮刚开始,还没有任务线记录。'
1924
+ : '这个会话还没有任务线。'))
1925
+ return wrap
1926
+ }
1927
+ for (const run of [...facts.rows].reverse()) wrap.append(railRun(run))
1928
+ return wrap
1929
+ }
1930
+
1931
+ function railCard(session) {
1932
+ const facts = railFactsOf(session)
1933
+ const status = railStatusOf(session, facts)
1934
+ const card = el('button', `rail-card k-${status.kind}${session.sessionId === STATE.sessionId ? ' current' : ''}`)
1935
+ card.type = 'button'
1936
+
1937
+ const top = el('div', 'rail-card-top')
1938
+ top.append(el('span', `rail-dot ${status.dot}`.trim()))
1939
+ top.append(el('span', 'rail-state', status.text))
1940
+ top.append(el('span', 'rail-when', timeLabel(session.updatedAt) || '—'))
1941
+ card.append(top)
1942
+
1943
+ const title = el('div', 'rail-title', railTitleOf(session))
1944
+ title.title = title.textContent
1945
+ card.append(title)
1946
+
1947
+ card.append(el('div', `rail-now${status.kind === 'idle' || status.kind === 'done' ? ' idle' : ''}`,
1948
+ railNowOf(session, facts, status)))
1949
+
1950
+ const meta = el('div', 'rail-meta')
1951
+ meta.append(el('span', '', `${facts.rows.length} 条`))
1952
+ meta.append(el('span', '', `并行 ${facts.running.length}`))
1953
+ if (facts.queued.length > 0) meta.append(el('span', '', `排队 ${facts.queued.length}`))
1954
+ card.append(meta)
1955
+
1956
+ card.addEventListener('click', () => {
1957
+ STATE.railDetail = session.sessionId
1958
+ renderRail()
1959
+ })
1960
+ return card
1961
+ }
1962
+
1963
+ function railSignature() {
1964
+ const rows = STATE.schedules.map(session => {
1965
+ const facts = railFactsOf(session)
1966
+ return [
1967
+ session.sessionId,
1968
+ session.updatedAt ?? '',
1969
+ session.running ? 'on' : '',
1970
+ session.title || session.first || '',
1971
+ facts.approvals,
1972
+ facts.attention,
1973
+ facts.rows.map(run => `${run.id}:${laneSignature(run)}`).join(','),
1974
+ ].join(':')
1975
+ })
1976
+ return [STATE.railDetail || '', STATE.schedulesNote || '', rows.join('|')].join('#')
1977
+ }
1978
+
1979
+ function renderRail() {
1980
+ const sessions = STATE.schedules
1981
+ const detail = sessions.find(session => session.sessionId === STATE.railDetail)
1982
+ if (STATE.railDetail && !detail) STATE.railDetail = null
1983
+ let running = 0
1984
+ let waiting = 0
1985
+ for (const session of sessions) {
1986
+ const kind = railStatusOf(session, railFactsOf(session)).kind
1987
+ if (kind === 'running' || kind === 'queued') running += 1
1988
+ else if (kind === 'attention' || kind === 'approval') waiting += 1
1989
+ }
1990
+ const busy = running + waiting
1991
+ railCountEl.textContent = String(busy)
1992
+ railCountEl.hidden = busy === 0
1993
+ const headParts = [`${sessions.length} 个会话`]
1994
+ if (running > 0) headParts.push(`在跑 ${running}`)
1995
+ if (waiting > 0) headParts.push(`等你 ${waiting}`)
1996
+ railFactsEl.textContent = sessions.length === 0 ? '' : headParts.join(' · ')
1997
+
1998
+ const signature = railSignature()
1999
+ if (signature === STATE.railSig) return
2000
+ STATE.railSig = signature
2001
+
2002
+ if (sessions.length === 0) {
2003
+ railBodyEl.replaceChildren(el('p', 'rail-empty', STATE.schedulesNote
2004
+ ? `读不到会话列表:${STATE.schedulesNote}`
2005
+ : STATE.mode === 'chat' ? '读取会话…' : '还不能读取会话。'))
2006
+ return
2007
+ }
2008
+ railBodyEl.replaceChildren(detail ? railDetailBody(detail) : railGridOf(sessions))
2009
+ }
2010
+
2011
+ function railGridOf(sessions) {
2012
+ const grid = el('div', 'rail-grid')
2013
+ for (const session of sessions) grid.append(railCard(session))
2014
+ return grid
2015
+ }
2016
+
2017
+ /** Elapsed clocks inside the open card detail keep ticking between polls. */
2018
+ function tickRailClocks() {
2019
+ for (const node of railBodyEl.querySelectorAll('.rail-elapsed[data-start]')) {
2020
+ const started = Number(node.dataset.start)
2021
+ if (!Number.isFinite(started)) continue
2022
+ const finished = node.dataset.finish ? Number(node.dataset.finish) : Date.now()
2023
+ if (!Number.isFinite(finished)) continue
2024
+ node.textContent = formatClock(finished - started)
2025
+ }
2026
+ }
2027
+
2028
+ let railTimer = 0
2029
+ function queueRail() {
2030
+ if (railTimer) return
2031
+ railTimer = setTimeout(() => {
2032
+ railTimer = 0
2033
+ renderRail()
2034
+ }, 120)
2035
+ }
2036
+
2037
+ function setRail(collapsed, { persist = true } = {}) {
2038
+ document.body.classList.toggle('rail-collapsed', collapsed)
2039
+ document.body.classList.toggle('rail-open', !collapsed)
2040
+ railToggleEl.textContent = collapsed ? '‹' : '›'
2041
+ railToggleEl.setAttribute('aria-label', collapsed ? '展开调度' : '收起调度')
2042
+ railToggleEl.title = collapsed ? '展开调度' : '收起调度'
2043
+ if (persist) {
2044
+ try { localStorage.setItem(RAIL_KEY, collapsed ? '1' : '0') } catch {}
2045
+ }
2046
+ }
2047
+
2048
+ /** A stored choice wins; otherwise a narrow screen starts collapsed. */
2049
+ function restoreRail() {
2050
+ let stored = null
2051
+ try { stored = localStorage.getItem(RAIL_KEY) } catch {}
2052
+ if (stored === '1' || stored === '0') setRail(stored === '1', { persist: false })
2053
+ else setRail(window.innerWidth <= 720, { persist: false })
2054
+ }
2055
+
2056
+ async function loadSchedules() {
2057
+ if (STATE.schedulesBusy || !STATE.token) return
2058
+ STATE.schedulesBusy = true
2059
+ try {
2060
+ const data = await api('/api/console/schedules')
2061
+ STATE.schedules = Array.isArray(data?.sessions) ? data.sessions : []
2062
+ STATE.schedulesNote = data?.reason || null
2063
+ } catch (error) {
2064
+ STATE.schedulesNote = messageOf(error)
2065
+ } finally {
2066
+ STATE.schedulesBusy = false
2067
+ renderRail()
2068
+ }
2069
+ }
2070
+
1599
2071
  function syncStopAll() {
1600
2072
  const active = STATE.runs.filter(run => !isTerminal(run.status))
1601
2073
  stopAllEl.hidden = active.length === 0
1602
2074
  stopAllEl.disabled = STATE.mode !== 'chat' || active.length === 0 || STATE.stopAllBusy
1603
- stopAllEl.textContent = STATE.stopAllBusy ? '正在停止…' : '停止这一轮'
2075
+ stopAllEl.textContent = STATE.stopAllBusy ? '停止中…' : '停止这一轮'
1604
2076
  }
1605
2077
 
1606
2078
  async function stopRun(runId) {
@@ -1645,17 +2117,17 @@
1645
2117
  function currentAction(run) {
1646
2118
  const subtasks = Array.isArray(run.subtasks) ? run.subtasks : []
1647
2119
  if (STATE.cancelRequested.has(run.id) && !isTerminal(run.status)) return '已请求停止,等宿主确认'
1648
- if (run.status === 'queued') return '排队,等前一条任务线让出位置'
1649
- if (run.status === 'planning') return '正在拆步骤'
1650
- if (run.status === 'aggregating') return '正在汇总各步骤的结果'
2120
+ if (run.status === 'queued') return '排队,等前面的任务线跑完'
2121
+ if (run.status === 'planning') return '拆分步骤中'
2122
+ if (run.status === 'aggregating') return '汇总各步骤的结果'
1651
2123
  if (run.status === 'completed') return '已交付,产物见汇总'
1652
2124
  if (isTerminal(run.status)) return run.status === 'cancelled' ? '已取消' : '没走通,原因见汇总'
1653
2125
  const running = subtasks.filter(subtask => subtask.status === 'running')
1654
2126
  if (running.length > 1) return `同时推进 ${running.length} 个步骤`
1655
- if (running.length === 1) return `正在做:${stepLabel(running[0])}`
2127
+ if (running.length === 1) return `正在做 ${stepLabel(running[0])}`
1656
2128
  const next = subtasks.find(subtask => subtask.status !== 'completed' && subtask.status !== 'failed')
1657
- if (next) return `准备:${stepLabel(next)}`
1658
- return '正在推进'
2129
+ if (next) return `接下来 ${stepLabel(next)}`
2130
+ return '进行中'
1659
2131
  }
1660
2132
 
1661
2133
  /** Tools the running steps report right now; empty when unknown, never guessed. */
@@ -1668,12 +2140,20 @@
1668
2140
 
1669
2141
  function laneSignature(run) {
1670
2142
  const steps = Array.isArray(run.subtasks)
1671
- ? run.subtasks.map(subtask => `${subtask.status}:${subtask.title}:${subtask.tool || ''}`).join(',')
2143
+ ? run.subtasks.map(subtask => [
2144
+ subtask.status, subtask.key || '', subtask.title, subtask.tool || '',
2145
+ subtask.startedAt || '', subtask.finishedAt || '',
2146
+ (subtask.waitingOn || []).join('.'), (subtask.dependsOn || []).join('.'),
2147
+ ].join(':')).join(',')
1672
2148
  : ''
1673
2149
  const attention = Array.isArray(run.attention)
1674
2150
  ? run.attention.map(item => `${item.id}:${item.question}`).join(',')
1675
2151
  : ''
1676
- return [run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || '', STATE.cancelRequested.has(run.id) ? 'stopping' : ''].join('|')
2152
+ return [
2153
+ run.status, steps, attention, run.report ? run.report.length : 0, run.finishedAt || '',
2154
+ STATE.cancelRequested.has(run.id) ? 'stopping' : '',
2155
+ run.limits?.maxParallel ?? '', run.queue?.position ?? '', run.queue?.waiting ? 'queued' : '',
2156
+ ].join('|')
1677
2157
  }
1678
2158
 
1679
2159
  /**
@@ -1945,7 +2425,7 @@
1945
2425
  const done = runs.every(run => isTerminal(run.status))
1946
2426
  const head = el('div', `lane-group-head${done ? ' done' : ''}`)
1947
2427
  head.append(el('span', 'dot'))
1948
- head.append(el('span', '', done ? `这一轮完成 · ${runs.length} 条任务线` : `推进中 · ${runs.length} 条任务线`))
2428
+ head.append(el('span', '', done ? `这一轮完成 · ${runs.length} 条任务线` : `进行中 · ${runs.length} 条任务线`))
1949
2429
  node.append(head)
1950
2430
  for (const run of runs) node.append(laneElement(run))
1951
2431
  if (done) node.append(summaryElement(runs))
@@ -1967,19 +2447,6 @@
1967
2447
  next.focus()
1968
2448
  try { next.setSelectionRange(next.value.length, next.value.length) } catch {}
1969
2449
  }
1970
- if (artifacts.length > 0) {
1971
- const chips = el('div', 'artifacts')
1972
- for (const artifact of artifacts) chips.append(artifactElement(artifact))
1973
- item.append(chips)
1974
- }
1975
- item.addEventListener('click', event => {
1976
- if (event.target.closest('a')) return
1977
- drawerClose()
1978
- entry.message.el?.scrollIntoView({ block: 'center', behavior: 'smooth' })
1979
- entry.message.el?.classList.add('flash')
1980
- setTimeout(() => entry.message.el?.classList.remove('flash'), 1200)
1981
- })
1982
- historyListEl.append(item)
1983
2450
  }
1984
2451
  renderAdvancedRuns()
1985
2452
  for (const id of [...STATE.cancelRequested]) {
@@ -1987,6 +2454,7 @@
1987
2454
  if (!run || isTerminal(run.status)) STATE.cancelRequested.delete(id)
1988
2455
  }
1989
2456
  syncStopAll()
2457
+ queueRail()
1990
2458
  renderHistory()
1991
2459
  }
1992
2460
 
@@ -2030,7 +2498,7 @@
2030
2498
  if (historyDrawerEl.hidden) return
2031
2499
  historyListEl.replaceChildren()
2032
2500
  if (STATE.sessionsBusy && STATE.sessions.length === 0) {
2033
- historyListEl.append(el('p', 'adv-note', '正在读取对话…'))
2501
+ historyListEl.append(el('p', 'adv-note', '读取中…'))
2034
2502
  return
2035
2503
  }
2036
2504
  if (STATE.sessionNote) {
@@ -2172,7 +2640,7 @@
2172
2640
  const failed = runs.filter(run => isTerminal(run.status) && run.status !== 'completed')
2173
2641
  const box = el('div', `summary${failed.length > 0 ? ' bad' : ''}`)
2174
2642
  box.append(el('div', 'st', failed.length > 0
2175
- ? `完成,${failed.length} 条任务线没走通`
2643
+ ? `完成 · ${failed.length} 条任务线失败`
2176
2644
  : `全部完成 · ${runs.length} 条任务线`))
2177
2645
 
2178
2646
  const first = runs.map(run => Date.parse(run.createdAt)).filter(Number.isFinite).sort((a, b) => a - b)[0]
@@ -2196,7 +2664,7 @@
2196
2664
  for (const item of artifacts) list.append(artifactElement(item))
2197
2665
  box.append(list)
2198
2666
  } else {
2199
- box.append(el('div', 'sd', '这次没有可以点开的产物;完整汇总在下面。'))
2667
+ box.append(el('div', 'sd', '这次没有能点开的产物,完整汇总在下面。'))
2200
2668
  }
2201
2669
 
2202
2670
  const details = el('details', 'report')
@@ -2204,7 +2672,7 @@
2204
2672
  for (const run of runs) {
2205
2673
  const block = el('div', 'sum-run')
2206
2674
  block.append(el('div', 'sum-run-title', `${run.goal || '任务线'} · ${laneStatusText(run)}`))
2207
- block.append(el('pre', '', run.report || '(这条任务线没有返回报告)'))
2675
+ block.append(el('pre', '', run.report || '(这条任务线没有报告)'))
2208
2676
  details.append(block)
2209
2677
  }
2210
2678
  box.append(details)
@@ -2218,7 +2686,7 @@
2218
2686
  function attentionElement(run, item) {
2219
2687
  const card = el('div', 'attention-card')
2220
2688
  card.append(el('div', 'kicker', '需要你决定'))
2221
- card.append(el('p', '', item.question || '运行中的任务在等一个决定'))
2689
+ card.append(el('p', '', item.question || '任务在等一个决定'))
2222
2690
  if (item.reason) card.append(el('p', 'reason', item.reason))
2223
2691
 
2224
2692
  const key = draftKey(run.id, item.id)
@@ -2274,7 +2742,7 @@
2274
2742
  body: { sessionId: STATE.sessionId, runId, attentionId, answer },
2275
2743
  })
2276
2744
  STATE.drafts.delete(key)
2277
- pushToast('决定已提交,任务线会在下一个边界应用。', 'ok')
2745
+ pushToast('已提交。任务线会在下一步用上这个决定。', 'ok')
2278
2746
  } catch (error) {
2279
2747
  pushToast(`提交失败:${messageOf(error)}`, 'err')
2280
2748
  } finally {
@@ -2353,7 +2821,7 @@
2353
2821
  }
2354
2822
  const tool = `${approval.toolName || ''}`.toLowerCase()
2355
2823
  const clip = value => (value.length > CALL_PREVIEW_LIMIT
2356
- ? { text: `${value.slice(0, CALL_PREVIEW_LIMIT)}\n…`, note: `共 ${value.length} 字符,这里先看前 ${CALL_PREVIEW_LIMIT} 字符。` }
2824
+ ? { text: `${value.slice(0, CALL_PREVIEW_LIMIT)}\n…`, note: `共 ${value.length} 字符,这里显示前 ${CALL_PREVIEW_LIMIT} 字符。` }
2357
2825
  : { text: value, note: '' })
2358
2826
  if (/write|edit|patch|apply|create|append/.test(tool)) {
2359
2827
  const body = pick('content', 'contents', 'text', 'new_string', 'newText', 'patch', 'diff')
@@ -2378,7 +2846,7 @@
2378
2846
  const target = approvalTarget(approval)
2379
2847
  if (target) card.append(el('div', 'where', `要动的位置:${target}`))
2380
2848
  const reason = approval.displayReason?.zh || approval.reason
2381
- card.append(el('p', 'why', reason || '宿主的工具调用被拦住了,需要你明确决定这一次。'))
2849
+ card.append(el('p', 'why', reason || '宿主拦住了这次工具调用,需要你决定。'))
2382
2850
  const preview = approvalCallPreview(approval)
2383
2851
  if (preview) {
2384
2852
  const details = el('details', 'call')
@@ -2418,8 +2886,8 @@
2418
2886
  const left = expiresAt - Date.now()
2419
2887
  node.classList.toggle('soon', left > 0 && left <= 60_000)
2420
2888
  node.classList.toggle('over', left <= 0)
2421
- if (left <= 0) node.textContent = `已超过有效期(${timeLabel(expiresAt)}),宿主会按拒绝处理;再发起会重新询问。`
2422
- else node.textContent = `剩余有效时间 ${formatClock(left)}(约到 ${timeLabel(expiresAt)})`
2889
+ if (left <= 0) node.textContent = `已过有效期(${timeLabel(expiresAt)}),宿主按拒绝处理。再发起会重新询问。`
2890
+ else node.textContent = `还剩 ${formatClock(left)}(约到 ${timeLabel(expiresAt)})`
2423
2891
  }
2424
2892
 
2425
2893
  function updateApprovalClocks() {
@@ -2431,8 +2899,8 @@
2431
2899
  entry.node.querySelector('.options')?.remove()
2432
2900
  const state = entry.node.querySelector('.state')
2433
2901
  if (!state) return
2434
- if (entry.decided === 'allow') state.textContent = '已允许这一次(只对这一条调用生效)'
2435
- else if (entry.decided === 'allow-tool') state.textContent = `已允许,并在本会话内放行 ${entry.approval?.toolName || '这个工具'}(换对话后恢复询问)`
2902
+ if (entry.decided === 'allow') state.textContent = '已允许这一次。只对这一条调用生效。'
2903
+ else if (entry.decided === 'allow-tool') state.textContent = `已允许,本会话内 ${entry.approval?.toolName || '这个工具'} 不再询问;换对话后恢复。`
2436
2904
  else if (entry.decided === 'reject') state.textContent = '已拒绝'
2437
2905
  else if (entry.decided === 'expired') state.textContent = '已过有效期,宿主按拒绝处理'
2438
2906
  else if (entry.decided === 'cancelled') state.textContent = '没有回答,按拒绝处理'
@@ -2474,22 +2942,22 @@
2474
2942
  if (!entry || entry.decided) return
2475
2943
  const state = entry.node.querySelector('.state')
2476
2944
  for (const button of entry.node.querySelectorAll('button')) button.disabled = true
2477
- const pending = { allow: '正在允许这一次…', 'allow-tool': '正在允许这个工具…', reject: '正在拒绝…' }
2478
- if (state) state.textContent = pending[decision] || '正在提交…'
2945
+ const pending = { allow: '允许中…', 'allow-tool': '放行中…', reject: '拒绝中…' }
2946
+ if (state) state.textContent = pending[decision] || '提交中…'
2479
2947
  try {
2480
2948
  await api('/api/console/approval', { method: 'POST', body: { id, decision } })
2481
2949
  entry.decided = decision
2482
2950
  settleApprovalNode(entry)
2483
2951
  const done = {
2484
- allow: '已允许这一次;只对这一条调用生效。',
2485
- 'allow-tool': '已允许:本会话内同一个工具不再询问(换对话后恢复)。',
2952
+ allow: '已允许这一次,只对这一条调用生效。',
2953
+ 'allow-tool': '已允许。本会话内这个工具不再询问,换对话后恢复。',
2486
2954
  reject: '已拒绝这一条调用。',
2487
2955
  }
2488
2956
  pushToast(done[decision] || '已提交。', 'ok')
2489
2957
  } catch (error) {
2490
2958
  for (const button of entry.node.querySelectorAll('button')) button.disabled = false
2491
- if (state) state.textContent = `没有提交成功:${messageOf(error)}`
2492
- pushToast(`审批没有提交成功:${messageOf(error)}`, 'err')
2959
+ if (state) state.textContent = `提交失败:${messageOf(error)}`
2960
+ pushToast(`审批没提交上:${messageOf(error)}`, 'err')
2493
2961
  }
2494
2962
  }
2495
2963
 
@@ -2509,7 +2977,7 @@
2509
2977
  if (data.report) renderMarkdownInto(dialogReportEl, data.report)
2510
2978
  else {
2511
2979
  dialogReportEl.textContent = ''
2512
- dialogReportEl.append(el('p', '', '(这个 run 还没有报告)'))
2980
+ dialogReportEl.append(el('p', '', '(这条任务线还没有报告)'))
2513
2981
  }
2514
2982
  reportDialogEl.showModal()
2515
2983
  } catch (error) {
@@ -2531,8 +2999,10 @@
2531
2999
  if (frame.sessionId && frame.sessionId !== STATE.sessionId) {
2532
3000
  setSession(frame.sessionId)
2533
3001
  STATE.approvals.clear()
3002
+ STATE.railDetail = null
2534
3003
  clearMessages()
2535
3004
  renderEmpty()
3005
+ loadSchedules()
2536
3006
  }
2537
3007
  break
2538
3008
  case 'stream.snapshot':
@@ -2571,9 +3041,10 @@
2571
3041
  if (frame.action === 'asked' && approval && approval.id) {
2572
3042
  seatApproval(approval)
2573
3043
  refreshNotices({ toastNew: true })
2574
- pushToast('有一个工具调用在等你决定。', 'warn')
3044
+ pushToast('有工具调用等你决定。', 'warn')
3045
+ queueRail()
2575
3046
  } else if (frame.action === 'auto') {
2576
- pushToast(`已按本会话的许可放行 ${frame.toolName || '这个工具'},没有再打断你。`, 'ok')
3047
+ pushToast(`已放行 ${frame.toolName || '这个工具'},本会话内不再询问。`, 'ok')
2577
3048
  } else if ((frame.action === 'decided' || frame.action === 'expired') && frame.id) {
2578
3049
  const entry = STATE.approvals.get(frame.id)
2579
3050
  if (entry) {
@@ -2584,6 +3055,7 @@
2584
3055
  : frame.outcome === 'rejected' ? 'reject' : 'cancelled'
2585
3056
  settleApprovalNode(entry)
2586
3057
  refreshNotices()
3058
+ queueRail()
2587
3059
  }
2588
3060
  }
2589
3061
  break
@@ -2606,10 +3078,10 @@
2606
3078
  if (frame.code === 'follow-failed' || frame.code === 'state-failed') {
2607
3079
  setConn('warn', '流中断')
2608
3080
  }
2609
- pushToast(frame.message || '控制台流发生错误', 'err')
3081
+ pushToast(frame.message || '控制台连接出错', 'err')
2610
3082
  break
2611
3083
  case 'truncated':
2612
- pushToast('有一段历史过大,已截断显示。', 'err')
3084
+ pushToast('历史太长,只显示了一部分。', 'err')
2613
3085
  break
2614
3086
  case 'closed':
2615
3087
  setConn('warn', '已关闭')
@@ -2833,6 +3305,7 @@
2833
3305
  refreshNotices()
2834
3306
  if (STATE.messages.length === 0) renderEmpty()
2835
3307
  loadTools()
3308
+ loadSchedules()
2836
3309
  wizardLoad({ probe: false, auto: true })
2837
3310
  }
2838
3311
 
@@ -2923,7 +3396,7 @@
2923
3396
  chip.append(el('span', 'dot'))
2924
3397
  chip.append(el('span', '', item.label))
2925
3398
  chip.append(el('span', 'env-value', item.value || ''))
2926
- chip.append(el('span', 'env-action', '点这里处理'))
3399
+ chip.append(el('span', 'env-action', '去处理'))
2927
3400
  chip.addEventListener('click', () => wizardOpen(item.action?.step || 1))
2928
3401
  envItemsEl.append(chip)
2929
3402
  }
@@ -3037,9 +3510,9 @@
3037
3510
  }
3038
3511
 
3039
3512
  function renderWizardStep1() {
3040
- wizardBodyEl.append(el('p', 'wiz-lead', '先看看宿主和环境是否准备好了。不通过的项可以直接点“点这里处理”,不需要读错误码。'))
3513
+ wizardBodyEl.append(el('p', 'wiz-lead', '先检查宿主和环境。没通过的项直接点“去处理”。'))
3041
3514
  if (!WIZ.status) {
3042
- wizardBodyEl.append(WIZ.statusPending > 0 ? wizardBusyNode('正在检查环境…') : el('p', 'wiz-note', '还没有读到检查结果。'))
3515
+ wizardBodyEl.append(WIZ.statusPending > 0 ? wizardBusyNode('检查中…') : el('p', 'wiz-note', '还没有读到检查结果。'))
3043
3516
  } else {
3044
3517
  const list = el('div', 'wiz-checks')
3045
3518
  for (const item of WIZ.status.environment || []) {
@@ -3052,7 +3525,7 @@
3052
3525
  if (item.hint) body.append(el('div', 'hint', item.hint))
3053
3526
  row.append(body)
3054
3527
  if (!item.ok && item.action) {
3055
- const button = el('button', '', '点这里处理')
3528
+ const button = el('button', '', '去处理')
3056
3529
  button.type = 'button'
3057
3530
  button.addEventListener('click', () => wizardHandleAction(item.action))
3058
3531
  row.append(button)
@@ -3061,7 +3534,7 @@
3061
3534
  }
3062
3535
  wizardBodyEl.append(list)
3063
3536
  if (WIZ.status.profile?.patchPath) {
3064
- wizardBodyEl.append(el('p', 'wiz-note', `配置文件:${WIZ.status.profile.patchPath}。写入前会自动备份,失败可以一键回滚。`))
3537
+ wizardBodyEl.append(el('p', 'wiz-note', `配置文件:${WIZ.status.profile.patchPath}。写入前会备份,出问题可以回滚。`))
3065
3538
  }
3066
3539
  }
3067
3540
  const error = wizardErrorNode()
@@ -3103,7 +3576,7 @@
3103
3576
 
3104
3577
  function renderWizardStep2() {
3105
3578
  const status = WIZ.status
3106
- wizardBodyEl.append(el('p', 'wiz-lead', '填你的 OpenAI 兼容端点。默认值已经填好,通常只需要粘贴 key。'))
3579
+ wizardBodyEl.append(el('p', 'wiz-lead', '填 OpenAI 兼容端点。默认值已经填好,一般只要粘贴 key。'))
3107
3580
  const form = el('div', 'wiz-form')
3108
3581
  form.append(wizardField('provider', '提供商名', 'text', 'haoduo', '小写字母、数字、短横线,会作为配置里的提供方 id。'))
3109
3582
  form.append(wizardField('baseURL', 'Base URL', 'text', 'https://byte.haoduotoken.com/v1', 'OpenAI 兼容端点,通常以 /v1 结尾。'))
@@ -3121,7 +3594,7 @@
3121
3594
  input.value = WIZ.form.apiKey ?? ''
3122
3595
  input.placeholder = status?.key?.configured
3123
3596
  ? `已保存 ${status.key.mask || '(内容不可回读)'},留空则沿用`
3124
- : '粘贴你的 API key'
3597
+ : '粘贴 API key'
3125
3598
  input.addEventListener('input', () => {
3126
3599
  WIZ.form.apiKey = input.value
3127
3600
  WIZ.formTouched = true
@@ -3132,7 +3605,7 @@
3132
3605
  badge.id = 'wizKeyBadge'
3133
3606
  row.append(input, badge)
3134
3607
  keyWrap.append(labelEl, row)
3135
- keyWrap.append(el('div', 'wiz-note', 'key 只写入宿主凭据库(或你已有的用户环境变量);不会写进仓库、配置或日志,页面不显示完整值。'))
3608
+ keyWrap.append(el('div', 'wiz-note', 'key 只写入宿主凭据库(或你已有的用户环境变量),不写进仓库、配置和日志,页面也不显示完整值。'))
3136
3609
  form.append(keyWrap)
3137
3610
  wizardBodyEl.append(form)
3138
3611
 
@@ -3176,7 +3649,7 @@
3176
3649
  function renderWizardStep3() {
3177
3650
  const preview = WIZ.preview
3178
3651
  if (!preview) {
3179
- wizardBodyEl.append(el('p', 'wiz-note', '先回到上一步做一次检查。'))
3652
+ wizardBodyEl.append(el('p', 'wiz-note', '回到上一步检查一次。'))
3180
3653
  wizardFootEl.replaceChildren()
3181
3654
  const back = el('button', 'wiz-secondary', '返回')
3182
3655
  back.type = 'button'
@@ -3184,7 +3657,7 @@
3184
3657
  wizardFootEl.append(back)
3185
3658
  return
3186
3659
  }
3187
- wizardBodyEl.append(el('p', 'wiz-lead', '这是将要写入的摘要。你不需要看 YAML;写入前会自动备份,失败可以一键回滚。'))
3660
+ wizardBodyEl.append(el('p', 'wiz-lead', '这是要写入的内容。不用看 YAML;写入前会备份,出问题可以回滚。'))
3188
3661
  const list = el('ul', 'wiz-summary')
3189
3662
  for (const line of preview.summary || []) list.append(el('li', '', line))
3190
3663
  wizardBodyEl.append(list)
@@ -3200,12 +3673,12 @@
3200
3673
  add('模型', preview.model)
3201
3674
  add('key', `${preview.key.mask || '沿用已保存的 key'}(引用 ${preview.key.ref})`)
3202
3675
  add('配置文件', preview.target.patchPath)
3203
- add('备份', '写入前保存;可在下一步点“回滚上次写入”恢复')
3676
+ add('备份', '写入前保存,下一步可以回滚')
3204
3677
  wizardBodyEl.append(kv)
3205
3678
 
3206
3679
  const error = wizardErrorNode()
3207
3680
  if (error) wizardBodyEl.append(error)
3208
- if (WIZ.busy === 'save') wizardBodyEl.append(wizardBusyNode('正在写入配置并保存 key…'))
3681
+ if (WIZ.busy === 'save') wizardBodyEl.append(wizardBusyNode('写入中…'))
3209
3682
  wizardBodyEl.append(el('p', 'wiz-note', preview.note || ''))
3210
3683
 
3211
3684
  wizardFootEl.replaceChildren()
@@ -3258,7 +3731,7 @@
3258
3731
  function renderWizardStep4() {
3259
3732
  const trial = WIZ.trial
3260
3733
  if (WIZ.busy === 'trial') {
3261
- wizardBodyEl.append(wizardBusyNode('正在临时目录里跑一个小任务(建文件并读回)…'))
3734
+ wizardBodyEl.append(wizardBusyNode('在临时目录建一个文件再读回来…'))
3262
3735
  wizardBodyEl.append(el('p', 'wiz-note', '不会碰你的项目目录。模型回复和工具调用会显示在下面。'))
3263
3736
  wizardFootEl.replaceChildren()
3264
3737
  const again = el('button', 'wiz-secondary', '试跑中…')
@@ -3269,7 +3742,7 @@
3269
3742
  }
3270
3743
 
3271
3744
  if (!trial) {
3272
- wizardBodyEl.append(el('p', 'wiz-lead', '最后一步:在系统临时目录里建一个文件并读回。它不会碰你的真实项目。'))
3745
+ wizardBodyEl.append(el('p', 'wiz-lead', '最后一步:在系统临时目录建一个文件再读回来,不碰你的项目。'))
3273
3746
  if (WIZ.saved) {
3274
3747
  const kv = el('div', 'wiz-kv')
3275
3748
  const add = (label, value) => {
@@ -3299,12 +3772,12 @@
3299
3772
  verdict.append(el('span', 'big', trial.ok ? '✓' : '!'))
3300
3773
  const text = el('div')
3301
3774
  text.append(el('div', 't', trial.ok
3302
- ? '试跑成功:它真的在临时目录里干了活。'
3775
+ ? '试跑通过:文件建好,也读回来了。'
3303
3776
  : (emptyRun ? '试跑没有跑起来' : '试跑没有完全成功')))
3304
3777
  text.append(el('div', 'd', trial.ok
3305
3778
  ? `用时 ${(trial.elapsedMs / 1000).toFixed(1)} 秒 · 会话 ${shortId(trial.sessionId)}`
3306
3779
  : (emptyRun
3307
- ? '这一轮没有模型回复。宿主可能还没切换到新模型,点“重新试跑”再来一次。'
3780
+ ? '这一轮没有模型回复。宿主可能还没换到新模型,点“重新试跑”再试。'
3308
3781
  : (trial.hint || '看下面的步骤和提示。'))))
3309
3782
  verdict.append(text)
3310
3783
  wizardBodyEl.append(verdict)
@@ -3387,13 +3860,13 @@
3387
3860
  try {
3388
3861
  const data = await api('/api/console/wizard/trial', { method: 'POST', body: {} })
3389
3862
  WIZ.trial = data
3390
- if (data.ok) pushToast('试跑成功:它真的在临时目录里干了活。', 'ok')
3863
+ if (data.ok) pushToast('试跑通过:文件建好,也读回来了。', 'ok')
3391
3864
  else pushToast('试跑没成功,按提示处理。', 'err')
3392
3865
  await wizardLoad({ probe: false })
3393
3866
  } catch (error) {
3394
3867
  WIZ.error = {
3395
3868
  message: messageOf(error),
3396
- hint: error.hint || (!error.status ? '宿主可能正在热加载配置,等两秒再点一次“开始试跑”。' : null),
3869
+ hint: error.hint || (!error.status ? '宿主可能在热加载配置,等两秒再点“开始试跑”。' : null),
3397
3870
  code: error.code,
3398
3871
  }
3399
3872
  } finally {
@@ -3435,7 +3908,7 @@
3435
3908
  else setConn('warn', '未连接')
3436
3909
  } catch (error) {
3437
3910
  if (error.status === 401) {
3438
- showGate('令牌无效或已轮换,请重新读取 console.json。')
3911
+ showGate('token 无效或已换新,重新读一次 console.json。')
3439
3912
  return
3440
3913
  }
3441
3914
  setMode('unavailable', { chat: false, reason: `${messageOf(error)}${error.hint ? `\n${error.hint}` : ''}` })
@@ -3494,7 +3967,7 @@
3494
3967
  } catch (error) {
3495
3968
  if (controller.signal.aborted) return
3496
3969
  if (error.status === 401) {
3497
- showGate('令牌无效或已轮换,请重新读取 console.json。')
3970
+ showGate('token 无效或已换新,重新读一次 console.json。')
3498
3971
  return
3499
3972
  }
3500
3973
  setConn('warn', '重连中')
@@ -3549,6 +4022,7 @@
3549
4022
  setSession(data.sessionId)
3550
4023
  STATE.approvals.clear()
3551
4024
  STATE.cancelRequested.clear()
4025
+ STATE.railDetail = null
3552
4026
  clearMessages()
3553
4027
  STATE.runs = []
3554
4028
  renderLanes()
@@ -3556,6 +4030,7 @@
3556
4030
  renderEmpty()
3557
4031
  renderTools(null)
3558
4032
  loadTools()
4033
+ loadSchedules()
3559
4034
  pushToast('已开始新对话。', 'ok')
3560
4035
  connectEvents()
3561
4036
  } catch (error) {
@@ -3698,10 +4173,19 @@
3698
4173
 
3699
4174
  newChatEl.addEventListener('click', newConversation)
3700
4175
  stopAllEl.addEventListener('click', stopAllRuns)
4176
+ railToggleEl.addEventListener('click', () => {
4177
+ setRail(!document.body.classList.contains('rail-collapsed'))
4178
+ })
4179
+ restoreRail()
4180
+ renderRail()
3701
4181
  setInterval(() => {
3702
4182
  tickLaneClocks()
4183
+ tickRailClocks()
3703
4184
  updateApprovalClocks()
3704
4185
  }, 1000)
4186
+ setInterval(() => {
4187
+ if (STATE.mode === 'chat') loadSchedules()
4188
+ }, 5000)
3705
4189
  $('historyOpen').addEventListener('click', () => drawerOpen('history'))
3706
4190
  $('advancedOpen').addEventListener('click', () => drawerOpen('advanced'))
3707
4191
  for (const button of document.querySelectorAll('[data-close]')) {