@duanz/pi-d-live 1.1.10 → 1.1.12

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 +27 -12
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -327,10 +327,17 @@ export function bashIntent(cmd: unknown): string {
327
327
  }
328
328
 
329
329
  const CMD_SYS = `你看到的是 AI 助手刚刚执行的一条命令,以及它执行前在想什么。
330
- 用一句中文说出这条命令的**目的**:他想确认什么、想查清什么、为了把哪件事往前推。要具体到对象,别只说「查一下」「跑一下」「核对一下」这种空话,说得口语、有画面感。
330
+ 用一句中文说出这条命令的**目的**:要确认什么、要查清什么、把哪件事往前推。要具体到对象,别只说「查一下」「跑一下」「核对一下」这种空话,说得口语、有画面感。
331
331
  规则:24 字以内;句尾加标点(…… 或 。);带 1~2 个贴切的 emoji,句中穿插或句尾收一下都行,让语气轻快些;不要出现命令名、参数、端口、脚本名、文件名、英文串、缩写字母——别说「跑 palette_check 脚本」,要说「核对一下页面配色有没有跑偏」这种能听懂目的的话;不要引号和编号。
332
+ 不许用人称:不出现「我/我们/您/你/他/她」,用没主语的说法,比如「正在核对页面配色」「这就去翻那份记录」。
333
+ 只描述这条命令本身在干嘛,绝不把上面这些要求当成命令目的复述出来(比如「想让我用一句话说明这条命令的目的」是错的)。
332
334
  只输出这一句话。`;
333
335
 
336
+ /** 模型偶尔把指令本身当命令目的念出来,或用人称写句子——这种丢掉,退回老实描述 */
337
+ function badIntent(line: string): boolean {
338
+ return /[我您你他她]/.test(line) || /一句话|这条命令|这条指令|想让|只输出|上面这些/.test(line);
339
+ }
340
+
334
341
  /** 让模型说清这条命令到底想干嘛;超时或失败返回空串,由 bashIntent 规则兜底。 */
335
342
  async function cmdIntent(ctx: any, cmd: string, hint = ""): Promise<string> {
336
343
  const model = pickModel(ctx);
@@ -347,7 +354,7 @@ async function cmdIntent(ctx: any, cmd: string, hint = ""): Promise<string> {
347
354
  {
348
355
  role: "user",
349
356
  content: [
350
- { type: "text", text: (hint ? `他刚才在想:${hint.slice(-300)}\n\n` : "") + `执行的命令:${text.slice(0, 800)}` },
357
+ { type: "text", text: (hint ? `动手前在想:${hint.slice(-300)}\n\n` : "") + `执行的命令:${text.slice(0, 800)}` },
351
358
  ],
352
359
  timestamp: Date.now(),
353
360
  },
@@ -363,7 +370,8 @@ async function cmdIntent(ctx: any, cmd: string, hint = ""): Promise<string> {
363
370
  .map((c: any) => c.text)
364
371
  .join("")
365
372
  .trim();
366
- return out.split("\n")[0].replace(/^[-•*\d.、)\s]+/, "").replace(/[""'']/g, "").slice(0, 40);
373
+ const one = out.split("\n")[0].replace(/^[-•*\d.、)\s]+/, "").replace(/[""'']/g, "").slice(0, 40);
374
+ return badIntent(one) ? "" : one;
367
375
  } catch {
368
376
  return "";
369
377
  }
@@ -372,6 +380,8 @@ async function cmdIntent(ctx: any, cmd: string, hint = ""): Promise<string> {
372
380
  const TOOL_SYS = `你看到的是 AI 助手刚要做的一件事(工具名 + 参数),以及它动手前的想法。
373
381
  用一句中文说清:在什么里面、找什么/看什么/改什么、想确认什么、为了什么。要具体到对象,别只说「看文件」「搜一下」这种空话。
374
382
  规则:24 字以内;句尾加标点(…… 或 。);带 1~2 个贴切的 emoji,句中穿插或句尾收一下都行,语气轻快些;不要出现参数名、缩写字母;不要引号和编号。
383
+ 不许用人称:不出现「我/我们/您/你/他/她」,用没主语的说法,比如「正在看那份记录」「这就去核对图片」。
384
+ 只描述这件工具活儿本身在干嘛,绝不把上面这些要求当成它的目的复述出来。
375
385
  只输出这一句话。`;
376
386
 
377
387
  /** 让模型说清这件工具活儿具体在干什么;超时或失败返回空串,由规则版兜底。 */
@@ -398,7 +408,7 @@ async function toolIntent(ctx: any, name: string, args: any, hint = ""): Promise
398
408
  {
399
409
  type: "text",
400
410
  text:
401
- (hint ? `他刚才在想:${hint.slice(-300)}\n\n` : "") +
411
+ (hint ? `动手前在想:${hint.slice(-300)}\n\n` : "") +
402
412
  `工具:${name}\n参数:${brief}`,
403
413
  },
404
414
  ],
@@ -416,7 +426,8 @@ async function toolIntent(ctx: any, name: string, args: any, hint = ""): Promise
416
426
  .map((c: any) => c.text)
417
427
  .join("")
418
428
  .trim();
419
- return out.split("\n")[0].replace(/^[-•*\d.、)\s]+/, "").replace(/[""'']/g, "").slice(0, 60);
429
+ const one = out.split("\n")[0].replace(/^[-•*\d.、)\s]+/, "").replace(/[""'']/g, "").slice(0, 60);
430
+ return badIntent(one) ? "" : one;
420
431
  } catch {
421
432
  return "";
422
433
  }
@@ -656,6 +667,8 @@ function humanFromSeg(seg: string): string {
656
667
  const m = t.match(/[^。!?!?;;\n]*[。!?!?]?\s*$/);
657
668
  t = (m && m[0] ? m[0] : t).trim();
658
669
  t = t.replace(/[`*_#>$|\\]/g, "").replace(/[""'']/g, "").replace(/\s+/g, " ").trim();
670
+ // 从想法里摘的兜底句去掉句首人称,别冒出「我准备查看…」
671
+ t = t.replace(/^(我|我们|您|你|他|她)/, "").trim();
659
672
  // 中文太少,或英文/技术符占多数 → 不适合播给用户
660
673
  const zh = (t.match(/[\u4e00-\u9fa5]/g) || []).length;
661
674
  if (zh < 4 || zh * 2 < t.length) return "";
@@ -948,24 +961,26 @@ export default function piWebLive(pi: ExtensionAPI) {
948
961
  // 先用规则版即时占位(零延迟),模型算出真正的意图后再把那一行改写掉
949
962
  const cmd = event?.args?.command;
950
963
  const key = tid || `t${Date.now()}`;
951
- const placeholder = humanFromSeg(s.seg) || bashIntent(cmd);
952
- emit({ kind: "tool", sid, tid: key, text: placeholder });
964
+ // 空泛兜底(看一眼/查一下)不落行:没实质想法就等模型改写,改不出来就整行不显示
965
+ const human = humanFromSeg(s.seg);
966
+ if (human) emit({ kind: "tool", sid, tid: key, text: human });
953
967
  const leak = s.seg || "";
954
968
  cmdIntent(ctx, cmd, leak)
955
969
  .then((said) => {
956
- 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 });
957
971
  })
958
972
  .catch(() => {});
959
973
  return;
960
974
  }
961
975
  {
962
976
  const key = tid || `t${Date.now()}`;
963
- const placeholder = humanFromSeg(s.seg) || describeTool(name, event?.args);
964
- emit({ kind: "tool", sid, tid: key, text: placeholder });
965
- // 规则版只说了「在文件里找 xxx」,再让模型说清在什么里找什么、为了啥
977
+ // 空泛兜底(看一眼/查一下)不落行:没实质想法就等模型改写,改不出来就整行不显示
978
+ const human = humanFromSeg(s.seg);
979
+ if (human) emit({ kind: "tool", sid, tid: key, text: human });
980
+ // 让模型说清这一步到底在干嘛;改不出来就整行不显示
966
981
  toolIntent(ctx, name, event?.args, s.seg || "")
967
982
  .then((said) => {
968
- if (said && said !== placeholder) emit({ kind: "tool-intent", sid, tid: key, text: said });
983
+ if (said && said !== human) emit({ kind: "tool-intent", sid, tid: key, text: said });
969
984
  })
970
985
  .catch(() => {});
971
986
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duanz/pi-d-live",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "把模型思考与工具调用实时改写成内心独白,推到 pi-web 界面顶部浮层",
5
5
  "type": "module",
6
6
  "keywords": [