@wendongfly/myhi 1.3.155 → 1.3.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/chat.html +34 -5
  2. package/package.json +1 -1
package/dist/chat.html CHANGED
@@ -402,8 +402,7 @@
402
402
  <button class="top-btn" onclick="openSettings()" title="设置">
403
403
  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 01-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
404
404
  </button>
405
- <button class="top-btn" id="ctx-chip" onclick="openCtxSheet()" title="会话数据:上下文水位 / 成本 / token 明细" style="display:none;font-size:0.7rem;color:var(--muted)">上下文</button>
406
- <button class="top-btn" onclick="showUsage()" title="用量" style="font-size:0.7rem;color:var(--muted)">用量</button>
405
+ <button class="top-btn" id="ctx-chip" onclick="openCtxSheet()" title="会话数据:上下文水位 / 成本 / token 明细" style="display:none;width:auto;padding:0 0.5rem;white-space:nowrap;font-size:0.7rem;color:var(--muted)">◈ --</button>
407
406
  <button class="top-btn" onclick="openFilePanel()" title="文件" style="font-size:0.7rem;color:var(--muted)">文件</button>
408
407
  <button class="top-btn" onclick="openSwitchSheet()" title="切换会话" style="font-size:0.7rem;color:var(--muted)">切换</button>
409
408
  <button class="top-btn" onclick="goBack()" title="返回">
@@ -2637,19 +2636,32 @@
2637
2636
  // claude 满 ~90% 会 auto-compact;myhi 显示水位 + 过阈值提示,让用户在任务节点**主动**压缩更可控。
2638
2637
  const CTX_WARN = 0.75, CTX_URGENT = 0.9;
2639
2638
  let _ctxIs1M = false; // stream 里 model 带 [1m] 后缀(如 claude-opus-5-5[1m])→ 精确判定 1M 窗口
2639
+ // 网关路由的第三方模型(glm-5.2 等)名字里没有 [1m],猜不住——会话数据面板里可手动指定窗口,
2640
+ // 存 localStorage 按会话隔离;优先级:手动指定 > [1m] 后缀 > >200k 兜底
2641
+ function ctxLimitOverride() {
2642
+ try {
2643
+ const v = parseInt(localStorage.getItem('myhi_ctx_limit_' + SESSION_ID), 10);
2644
+ if (v === 200_000 || v === 1_000_000) return v;
2645
+ } catch { /* ignore */ }
2646
+ return 0;
2647
+ }
2640
2648
  function ctxLimit(tokens) {
2649
+ const ov = ctxLimitOverride();
2650
+ if (ov) return ov;
2641
2651
  if (_ctxIs1M) return 1_000_000;
2642
2652
  // 没有 [1m] 标记时的兜底:200k 窗口装不下 >200k,超过即证明是 1M
2643
2653
  return tokens > 200_000 ? 1_000_000 : 200_000;
2644
2654
  }
2655
+ let _lastCtxTokens = 0;
2645
2656
  function ctxUpdate(tokens) {
2657
+ if (tokens > 0) _lastCtxTokens = tokens;
2646
2658
  const chip = document.getElementById('ctx-chip');
2647
2659
  if (!chip) return;
2648
2660
  if (!tokens || tokens <= 0) { chip.style.display = 'none'; return; }
2649
2661
  const limit = ctxLimit(tokens);
2650
2662
  const pct = Math.min(100, Math.round(tokens / limit * 100));
2651
2663
  chip.style.display = '';
2652
- chip.textContent = `上下文 ${pct}%`;
2664
+ chip.textContent = `◈ ${pct}%`;
2653
2665
  chip.style.color = pct >= 90 ? 'var(--red)' : pct >= 75 ? 'var(--yellow)' : 'var(--muted)';
2654
2666
  // 压缩快捷按钮同步高亮(agent 栏是 doSlashCmd('/compact'),PTY 栏是 doCompact())
2655
2667
  for (const sel of [
@@ -2701,16 +2713,26 @@
2701
2713
  const tokens = s.contextTokens || 0;
2702
2714
  let html = '';
2703
2715
 
2716
+ // 窗口手动切换(网关模型名不带 [1m],猜不住 → 让用户指定;跑查询前也可先设好)
2717
+ const limitButtons = (limit) => {
2718
+ const ov = ctxLimitOverride();
2719
+ const auto = ov ? '' : '(自动)';
2720
+ const btn = (v, label) => `<button onclick="ctxSetLimit(${v})" style="border:1px solid ${limit === v ? 'var(--blue2)' : 'var(--border)'};background:${limit === v ? 'var(--blue2)' : 'var(--bg)'};color:${limit === v ? '#fff' : 'var(--text2)'};border-radius:6px;padding:0.1rem 0.45rem;font-size:0.7rem;cursor:pointer">${label}</button>`;
2721
+ return `<span style="font-weight:400;font-size:0.68rem;color:var(--muted)">窗口${auto} ${btn(200_000, '200k')} ${btn(1_000_000, '1M')}</span>`;
2722
+ };
2723
+
2704
2724
  // ① 上下文水位
2705
2725
  if (tokens > 0) {
2706
2726
  const limit = ctxLimit(tokens);
2707
2727
  const pct = Math.min(100, Math.round(tokens / limit * 100));
2708
2728
  const barColor = pct >= 90 ? 'var(--red)' : pct >= 75 ? 'var(--yellow)' : 'var(--blue2)';
2709
- html += `<div ${C}><div ${H}>上下文水位</div>` +
2729
+ html += `<div ${C}><div ${H} style="display:flex;justify-content:space-between;align-items:center"><span>上下文水位</span>${limitButtons(limit)}</div>` +
2710
2730
  `<div style="background:var(--surface2);border-radius:6px;height:10px;overflow:hidden;margin-bottom:0.4rem"><div style="width:${pct}%;height:100%;background:${barColor};border-radius:6px;transition:width 0.4s"></div></div>` +
2711
2731
  `<div ${R}><span>${pct}%(${pct >= 90 ? '快满了,建议主动压缩' : pct >= 75 ? '建议任务节点压缩' : '健康'})</span><span ${V}>${(tokens / 1000).toFixed(1)}k / ${limit >= 1_000_000 ? '1M' : '200k'}</span></div></div>`;
2712
2732
  } else {
2713
- html += `<div ${C}><div ${H}>上下文水位</div><div ${R}><span style="color:var(--muted)">本轮还没跑过查询</span></div></div>`;
2733
+ html += `<div ${C}><div ${H} style="display:flex;justify-content:space-between;align-items:center"><span>上下文水位</span>${limitButtons(ctxLimit(0))}</div>` +
2734
+ `<div ${R}><span style="color:var(--muted)">还没跑过查询,跑一轮后显示水位</span></div>` +
2735
+ `<div ${R} style="margin-top:0.3rem"><span style="color:var(--muted);font-size:0.7rem">网关模型(如 glm-5.2)名字不带 [1m] 时请手动指定窗口</span></div></div>`;
2714
2736
  }
2715
2737
 
2716
2738
  // ② 累计用量(服务端权威账本)
@@ -2738,6 +2760,12 @@
2738
2760
  n = n || 0;
2739
2761
  return n >= 1_000_000 ? (n / 1_000_000).toFixed(2) + 'M' : n >= 1000 ? (n / 1000).toFixed(1) + 'k' : String(n);
2740
2762
  }
2763
+ // 手动指定上下文窗口:存 localStorage(按会话),刷新 chip 与面板
2764
+ window.ctxSetLimit = function(v) {
2765
+ try { localStorage.setItem('myhi_ctx_limit_' + SESSION_ID, String(v)); } catch { /* ignore */ }
2766
+ ctxUpdate(_lastCtxTokens || 0);
2767
+ openCtxSheet(); // 重开面板重渲染(重新拉数据)
2768
+ };
2741
2769
 
2742
2770
  // 服务端本地处理的 slash 命令(agent.js 拦截后只回一条 system/info、不 spawn claude、
2743
2771
  // 永远等不到 result)—— 这些不能进 thinking/working 态,否则没人把它清回来:
@@ -3842,6 +3870,7 @@
3842
3870
  socket.emit('agent:query', { prompt: '/clear' });
3843
3871
  addStatusMessage('已清除对话和 Claude 上下文');
3844
3872
  _ctxNudgeLevel = 0;
3873
+ _lastCtxTokens = 0;
3845
3874
  ctxUpdate(0); // 上下文已清空,水位指示复位
3846
3875
  } else {
3847
3876
  addStatusMessage('聊天记录已清除');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.155",
3
+ "version": "1.3.157",
4
4
  "description": "Web-based terminal sharing with chat UI — control your terminal from phone via LAN/Tailscale",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",