@duanz/pi-d-live 1.1.3 → 1.1.5

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 +33 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -85,13 +85,14 @@ function startEffortWatcher(emitFn: (p: Record<string, unknown>) => void) {
85
85
  const SYS = `把下面这段思考,改写成给用户看的进度解说:正在做什么、为什么这么做、做完会怎样。
86
86
 
87
87
  最重要的一条——每一句单独拎出来,也要让人看得懂“这是在为哪件事、做到哪一步”:
88
- - 句子里必须带出这件事本身,用 2~6 个字的短名字把目标点明,例如“思考条字句”“版本升级”“接线这套”“硬盘快满”;
88
+ - 目标短名必须从「这轮要办的事」里提炼,2~6 个字,说清在办什么,例如用户说“思考条看不出来在做什么”就取“思考条文案”,说“升级 pi web”就取“版本升级”,“硬盘快满”就取“清硬盘”;
89
89
  - 这个短名字要出现在每一句里(或紧挨着它的对象),不能只第一句有、后面全丢;
90
+ - 严禁拿目录名、项目代号、仓库名当目标名凑数,也严禁用“这边/这份/那头/动静/情况”这种没信息量的指代顶替目标;
90
91
  - 句子要带出这一步在干嘛/为什么这么干,而不是只报一个动作;
91
92
  - 禁止「先翻翻」「对一下」「这就改」「已确认」「跑通了」这种只有动作、没有对象的半截话,也禁止用「接着」「这下」「于是」开头却不交代主语。
92
93
 
93
- 反面例子(不要写成这样):先翻翻最近吐出来的几句。会话里的动静已经跑通了。这下页面那头一接回来。
94
- 正面例子(要写成这样):思考条字句还差点火候,先翻翻最近吐出来的几句。思考条这条线已经跑通了,页面那头一接回来就能看见。
94
+ 反面例子(不要写成这样):折腾折腾这边等抓取跑着。先翻翻最近吐出来的几句。会话里的动静已经跑通了。
95
+ 正面例子(要写成这样):思考条文案还差口气,先翻翻最近吐出来的几句。思考条文案改完了,页面一刷新就能看见。
95
96
 
96
97
  规则:
97
98
  - 第一句先交代这次要解决的是什么事、卡在哪(从输入里判断,不要照抄);
@@ -109,7 +110,7 @@ const SYS = `把下面这段思考,改写成给用户看的进度解说:正
109
110
  - 想不出内容就少写几句,不要凑数。
110
111
  只输出这些短句,每句一行。`;
111
112
 
112
- /** 当前会话所在目录名,当作「这件事」的拠点递给改写模型,免得它写出不知道在干嘛的句子 */
113
+ /** 当前会话所在目录名(只做兵底,不当目标名) */
113
114
  function projectOf(ctx: any): string {
114
115
  try {
115
116
  const cwd = String(ctx?.cwd || ctx?.sessionManager?.getCwd?.() || "");
@@ -119,6 +120,31 @@ function projectOf(ctx: any): string {
119
120
  }
120
121
  }
121
122
 
123
+ /** 取本会话最近一条用户消息,作为「这轮要办的事」递给改写模型,否则它只能编空话 */
124
+ function taskOf(ctx: any): string {
125
+ try {
126
+ const sm = ctx?.sessionManager;
127
+ const entries: any[] = sm?.getEntries?.() || [];
128
+ for (let i = entries.length - 1; i >= 0; i--) {
129
+ const e = entries[i];
130
+ const m = e?.message || e?.payload?.message || e;
131
+ if (m?.role !== "user") continue;
132
+ const c = m.content;
133
+ const txt =
134
+ typeof c === "string"
135
+ ? c
136
+ : Array.isArray(c)
137
+ ? c.filter((x: any) => x?.type === "text").map((x: any) => x.text).join(" ")
138
+ : "";
139
+ const t = String(txt).replace(/\s+/g, " ").trim();
140
+ if (t && !t.startsWith("【系统恢复】")) return t.slice(0, 160);
141
+ }
142
+ return "";
143
+ } catch {
144
+ return "";
145
+ }
146
+ }
147
+
122
148
  // 工具名 → 人话。不调模型,零延迟。
123
149
  const TOOL_LABEL: Record<string, string> = {
124
150
  read: "看一眼",
@@ -702,9 +728,9 @@ function rewrite(s: Sess, sid: string, text: string) {
702
728
  const model = pickModel(ctx);
703
729
  if (!model) return;
704
730
  const prior = s.history.slice(-4);
705
- const proj = projectOf(ctx);
706
- const projLine = proj ? `这件事的短名字可以参考目录名:${proj}\n` : "";
707
- const lead = projLine + (prior.length
731
+ const task = taskOf(ctx);
732
+ const taskLine = task ? `这轮要办的事(用户原话,目标短名从这里取):${task}\n` : "";
733
+ const lead = taskLine + (prior.length
708
734
  ? "前面已经说过(接着往下讲,别重复):\n" + prior.join("\n") + "\n\n这一段新的思考:\n"
709
735
  : "");
710
736
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duanz/pi-d-live",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "把模型思考与工具调用实时改写成内心独白,推到 pi-web 界面顶部浮层",
5
5
  "type": "module",
6
6
  "keywords": [