@duanz/pi-d-live 1.1.9 → 1.1.11

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/index.ts +34 -17
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -283,10 +283,11 @@ export function bashIntent(cmd: unknown): string {
283
283
  // 正则里带元字符的,别把符号本身当"要找的东西"
284
284
  if (/[\\^$*+?\[\](){}|]/.test(p)) p = "";
285
285
  const f = file.length ? baseName(file[file.length - 1]) : "";
286
- if (p && f) return `在 ${f} 里找「${p}」`;
287
- if (p) return `找「${p}」`;
288
- if (f) return `在 ${f} 里翻`;
289
- return "在文件里搜";
286
+ // 技术串(英文/路径/缩写)不外漏,只留看得懂的中文关键词
287
+ var human = function (x: string) { return !!x && /[\u4e00-\u9fa5]{2,}/.test(x) && !/[A-Za-z\/.\\]/.test(x); };
288
+ if (human(p) && human(f)) return `在${f}里找「${p}」`;
289
+ if (human(p)) return `找「${p}」`;
290
+ return "在文件里翻找";
290
291
  }
291
292
  // 访问接口:看路径语义
292
293
  if (/\bcurl\b/.test(c)) {
@@ -322,10 +323,7 @@ export function bashIntent(cmd: unknown): string {
322
323
  }
323
324
  }
324
325
  if (!label) return "跑一条命令";
325
- const target = rest
326
- .filter((w) => /^[a-z][a-z0-9-]{3,}$/i.test(w) && !CMD_WORDS.has(w.toLowerCase()))
327
- .pop();
328
- return target ? `${label} · ${target}` : label;
326
+ return label;
329
327
  }
330
328
 
331
329
  const CMD_SYS = `你看到的是 AI 助手刚刚执行的一条命令,以及它执行前在想什么。
@@ -357,7 +355,7 @@ async function cmdIntent(ctx: any, cmd: string, hint = ""): Promise<string> {
357
355
  },
358
356
  { cacheRetention: "none" },
359
357
  ),
360
- new Promise((r) => setTimeout(() => r(null), 5000)),
358
+ new Promise((r) => setTimeout(() => r(null), 12000)),
361
359
  ]);
362
360
  if (!res) return "";
363
361
  const out = (res.content || [])
@@ -410,7 +408,7 @@ async function toolIntent(ctx: any, name: string, args: any, hint = ""): Promise
410
408
  },
411
409
  { cacheRetention: "none" },
412
410
  ),
413
- new Promise((r) => setTimeout(() => r(null), 5000)),
411
+ new Promise((r) => setTimeout(() => r(null), 12000)),
414
412
  ]);
415
413
  if (!res) return "";
416
414
  const out = (res.content || [])
@@ -643,11 +641,28 @@ function describeTool(name: string, args: any): string {
643
641
  if (k === "path" || k === "url" || k === "uris") v = shortName(String(Array.isArray(v) ? v[0] : v));
644
642
  let s = String(v).replace(/\s+/g, " ").trim();
645
643
  if (s.length > 28) s = s.slice(0, 27) + "…";
644
+ // 路径/英文串/缩写不外漏,只拼看得懂的中文
645
+ if (!/[\u4e00-\u9fa5]/.test(s)) return label;
646
646
  return s ? `${label} ${s}` : label;
647
647
  }
648
648
  return label;
649
649
  }
650
650
 
651
+ /** 从动手前的中文想法里挑一句能给用户看的人话;挑不出返回空 */
652
+ function humanFromSeg(seg: string): string {
653
+ let t = String(seg || "").trim();
654
+ if (!t || isNoise(t)) return "";
655
+ // 只取最后一句:有句末标点就取那一截,没有就取整段
656
+ const m = t.match(/[^。!?!?;;\n]*[。!?!?]?\s*$/);
657
+ t = (m && m[0] ? m[0] : t).trim();
658
+ t = t.replace(/[`*_#>$|\\]/g, "").replace(/[""'']/g, "").replace(/\s+/g, " ").trim();
659
+ // 中文太少,或英文/技术符占多数 → 不适合播给用户
660
+ const zh = (t.match(/[\u4e00-\u9fa5]/g) || []).length;
661
+ if (zh < 4 || zh * 2 < t.length) return "";
662
+ if (t.length > 26) t = "…" + t.slice(-25);
663
+ return /[。!?!?]$/.test(t) ? t : t + "。";
664
+ }
665
+
651
666
  function shouldCut(s: string): boolean {
652
667
  if (s.length >= MAX_SEG) return true;
653
668
  if (s.length >= MIN_SEG && /[。!?!?\n]\s*$/.test(s)) return true;
@@ -933,24 +948,26 @@ export default function piWebLive(pi: ExtensionAPI) {
933
948
  // 先用规则版即时占位(零延迟),模型算出真正的意图后再把那一行改写掉
934
949
  const cmd = event?.args?.command;
935
950
  const key = tid || `t${Date.now()}`;
936
- const placeholder = bashIntent(cmd);
937
- emit({ kind: "tool", sid, tid: key, text: placeholder });
951
+ // 空泛兜底(看一眼/查一下)不落行:没实质想法就等模型改写,改不出来就整行不显示
952
+ const human = humanFromSeg(s.seg);
953
+ if (human) emit({ kind: "tool", sid, tid: key, text: human });
938
954
  const leak = s.seg || "";
939
955
  cmdIntent(ctx, cmd, leak)
940
956
  .then((said) => {
941
- if (said && said !== placeholder) emit({ kind: "tool-intent", sid, tid: key, text: said });
957
+ if (said && said !== human) emit({ kind: "tool-intent", sid, tid: key, text: said });
942
958
  })
943
959
  .catch(() => {});
944
960
  return;
945
961
  }
946
962
  {
947
963
  const key = tid || `t${Date.now()}`;
948
- const placeholder = describeTool(name, event?.args);
949
- emit({ kind: "tool", sid, tid: key, text: placeholder });
950
- // 规则版只说了「在文件里找 xxx」,再让模型说清在什么里找什么、为了啥
964
+ // 空泛兜底(看一眼/查一下)不落行:没实质想法就等模型改写,改不出来就整行不显示
965
+ const human = humanFromSeg(s.seg);
966
+ if (human) emit({ kind: "tool", sid, tid: key, text: human });
967
+ // 让模型说清这一步到底在干嘛;改不出来就整行不显示
951
968
  toolIntent(ctx, name, event?.args, s.seg || "")
952
969
  .then((said) => {
953
- if (said && said !== placeholder) emit({ kind: "tool-intent", sid, tid: key, text: said });
970
+ if (said && said !== human) emit({ kind: "tool-intent", sid, tid: key, text: said });
954
971
  })
955
972
  .catch(() => {});
956
973
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duanz/pi-d-live",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "把模型思考与工具调用实时改写成内心独白,推到 pi-web 界面顶部浮层",
5
5
  "type": "module",
6
6
  "keywords": [