@zhushanwen/pi-smart-context 0.4.2 → 0.4.4

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.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  - cross-model:调用 pi 原生 `compact()` 仅换模型与凭证——split-turn / fileOps / previousSummary 原生组装
11
11
  - **3 档阈值提醒**(默认 400K/500K/600K):`agent_settled` 越档检查,每档一次、多档合并、压缩后重置,nextTurn 投递(随下一次 prompt 注入,不自起 run);已提醒档位经 `pi.appendEntry` 落在 session entries(`smart-context:fired`),reload / 进程重启后从 entries 重建,同一档不会重复提醒;措辞是数据投递不是指令
12
12
  - **排除模型**(精准 `provider/modelId` 匹配):工具拒绝 + 不提醒 + 回落 pi 原生生成;切换跨界时注入一条可用性通知,downshift(切小窗模型将触线)时建议先压缩
13
- - **通知车道**:压缩结果 / 阈值提醒 / 模型切换四类通知统一走 nextTurn(custom role 随下次 prompt 注入,不自起 run)——工具压缩掐断的 turn 由 taiji runtime 在 `compaction_end` 判定后经投递内核追加续跑投递
13
+ - **通知投递路径**:压缩结果 / 阈值提醒 / 模型切换四类通知统一走 nextTurn(custom role 随下次 prompt 注入,不自起 run)——工具压缩掐断的 turn 由 taiji runtime 在 `compaction_end` 判定后经投递内核追加续跑投递
14
14
  - **健壮性**:摘要收缩校验、max-tokens 截断 fail-closed、接管失败 3 次熔断(本 session 内停止接管)、transcript 回查指针、压缩后最近文件内容重注入(≤5 文件/50K)、多轮压缩降智提示(累计压缩 ≥2 次后附加)
15
15
  - **subagent 进程**自动静默(`TAIJI_AGENT_SUBAGENT` 标记)
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-smart-context",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "taiji": {
@@ -36,8 +36,8 @@
36
36
  "pi-package"
37
37
  ],
38
38
  "dependencies": {
39
- "@zhushanwen/extension-protocol": "0.23.0",
40
39
  "@zhushanwen/pi-ext-guards": "0.5.0",
40
+ "@zhushanwen/extension-protocol": "0.26.0",
41
41
  "@zhushanwen/pi-extension-logger": "0.6.2",
42
42
  "@zhushanwen/pi-llm-shared": "0.12.0"
43
43
  },
@@ -72,7 +72,7 @@
72
72
  }
73
73
  },
74
74
  "scripts": {
75
- "test": "vitest run",
75
+ "test": "vitest run --pool=threads",
76
76
  "test:watch": "vitest"
77
77
  }
78
78
  }
@@ -128,7 +128,7 @@ describe("compact_context 工具(R2 降级态:fire-and-forget + 结果注入
128
128
  await tools[0].execute("t1", {}, undefined, undefined, makeCtx());
129
129
  expect(pi.sendMessage).toHaveBeenCalledTimes(1);
130
130
  const [message, options] = pi.sendMessage.mock.calls[0];
131
- // D4①:nextTurn 化——custom role 消息 + 不自起 run 的投递车道
131
+ // D4①:nextTurn 化——custom role 消息 + 不自起 run 的投递路径
132
132
  expect(message.customType).toBe("smart-context");
133
133
  expect(message.details).toEqual({ source: "compact-complete" });
134
134
  expect(options).toEqual({ triggerTurn: false, deliverAs: "nextTurn" });
@@ -138,7 +138,7 @@ describe("compact_context 工具(R2 降级态:fire-and-forget + 结果注入
138
138
  expect(text).toContain("500K");
139
139
  expect(text).toContain("24K");
140
140
  expect(text).toContain("compacted multiple times");
141
- // 旧车道(自起 run 的 user 消息)已退役:不再调用 sendUserMessage(mock 挂 spy,被调用即断言红)
141
+ // 旧投递路径(自起 run 的 user 消息)已退役:不再调用 sendUserMessage(mock 挂 spy,被调用即断言红)
142
142
  expect(pi.sendUserMessage).not.toHaveBeenCalled();
143
143
  });
144
144
 
@@ -151,7 +151,7 @@ describe("compact_context 工具(R2 降级态:fire-and-forget + 结果注入
151
151
  expect(pi.sendMessage.mock.calls[0][0].content).toContain("回退");
152
152
  });
153
153
 
154
- it("onError → 注入失败消息带重试指引(display:true 失败必须用户可见 + nextTurn 车道不自起 run)", async () => {
154
+ it("onError → 注入失败消息带重试指引(display:true 失败必须用户可见 + nextTurn 投递路径不自起 run)", async () => {
155
155
  const { pi, tools } = makePi();
156
156
  registerCompactContextTool(pi);
157
157
  const ctx = makeCtx((options) => options.onError(new Error("Nothing to compact")));
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * - agent_settled:越档检查 + marker 持久化(D15)+ nextTurn 投递一次性提醒(D3/D4①)
10
10
  * - model_select:跨界通知 + downshift 提醒(D5/D4①)
11
11
  *
12
- * 通知注入车道(D4①,delivery-ownership-kernel):四类通知全部经 notices.ts 的
12
+ * 通知投递路径(D4①,delivery-ownership-kernel):四类通知全部经 notices.ts 的
13
13
  * sendSmartContextNotice 走 nextTurn(随下一次 prompt 注入、不自起 run)——通知 run 不再
14
14
  * 抢占用户消息投递跑道;被压缩掐断的 turn 由 runtime 续跑投递兜底(D4②)。
15
15
  */
package/src/notices.ts CHANGED
@@ -33,13 +33,13 @@ export type SmartContextNoticeSource =
33
33
  | "model-downshift";
34
34
 
35
35
  /**
36
- * 注入一条 smart-context 通知(nextTurn 车道,不自起 run)。
36
+ * 注入一条 smart-context 通知(nextTurn 投递路径,不自起 run)。
37
37
  *
38
- * `deliverAs:'nextTurn'` 是投递车道(pi 实装分支序:nextTurn 分支先命中,`triggerTurn`
38
+ * `deliverAs:'nextTurn'` 是投递路径之一(pi 实装分支序:nextTurn 分支先命中,`triggerTurn`
39
39
  * 不再参与判定);`triggerTurn:false` 是意图的显式声明(双写防未来实现分支序漂移)。
40
- * `display:true` 使通知在对话流可见——分车道语义(D4①):compact-result 两条(complete/
40
+ * `display:true` 使通知在对话流可见——可见性按投递路径区分(D4①):compact-result 两条(complete/
41
41
  * failed)改造前即 display:true 系统消息,可见性保持;阈值提醒/模型跨界/downshift 三条
42
- * 改造前 display:false 静默(只进 LLM 上下文,不进对话流),随 nextTurn 车道统一转
42
+ * 改造前 display:false 静默(只进 LLM 上下文,不进对话流),随 nextTurn 投递路径统一转
43
43
  * display:true 可见。
44
44
  */
45
45
  export function sendSmartContextNotice(
package/src/reminder.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * 提醒与通知文案构造(D3/D4/D5/D13-12)。
3
3
  *
4
4
  * 全部为纯函数:文案 + 越档判定。注入由 src/index.ts / src/tool.ts 经 notices.ts 的
5
- * sendSmartContextNotice(nextTurn 车道,D4①)执行。
5
+ * sendSmartContextNotice(nextTurn 投递路径,D4①)执行。
6
6
  * 措辞原则(目标 3):提醒是数据投递不是指令——给三条件自查清单 + 明确的"可忽略"出口,
7
7
  * 避免 agent 见提醒就压缩。
8
8
  */
package/src/tool.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * (R2 实测 2026-08-22:tool execute 内 await ctx.compact() 不可行——AgentSession.compact
6
6
  * 开头的 abort() 会中止当前 agent 循环,挂起的 Promise 永不兑现、session 无 toolResult。
7
7
  * 故走 §3.2 降级态:execute 立即返回"压缩已启动",onComplete/onError 后经
8
- * sendSmartContextNotice 注入结果消息(nextTurn 车道,D4①——随下一次 prompt 注入,
8
+ * sendSmartContextNotice 注入结果消息(nextTurn 投递路径,D4①——随下一次 prompt 注入,
9
9
  * 不自起 run;此刻无进行中回合,compact 内部 abort 为 no-op)。
10
10
  * 压缩生成由 session_before_compact 接管 handler 完成(工具只触发,不生成)。
11
11
  *