pi-scenes 0.3.0 → 0.4.0

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
@@ -20,6 +20,7 @@ active resources = common layer ∪ current scene
20
20
  - **Common layer** — extensions + skills that stay loaded in *every* scenario (quota display, session carryover…)
21
21
  - **Scene layers** — per-scenario bundles (coding / office / writing…), loaded only while active
22
22
  - Switching rewrites `packages`/`skills` in `settings.json`, then `ctx.reload()` hot-reloads — **no pi restart, session untouched**
23
+ - Every switch stamps a persistent **status-bar badge** (`◆ coding`, or a per-scene `icon` like `💻 coding`) so the bar always answers *"which scene am I in"* — restored at session start, cleared by `/scene off`
23
24
  - The data model reserves an `extends` chain (with cycle detection) for future **parent → child scene** hierarchies
24
25
 
25
26
  ## Install
@@ -75,6 +76,7 @@ Edit it to fit your setup (each scene also gets a skill dir scaffold at `~/.pi/a
75
76
  "scenes": { // ── scene layers: stacked when active
76
77
  "coding": {
77
78
  "description": "coding",
79
+ "icon": "💻",
78
80
  "packages": ["npm:pi-carryover"],
79
81
  "skills": ["~/.pi/agent/scenes/coding/skills"]
80
82
  },
@@ -95,6 +97,8 @@ Drop `SKILL.md` folders (or `.md` files) into a scene's skill directory; the who
95
97
 
96
98
  A successful switch sets a persistent footer badge (`◆ coding`), restored automatically at every session start and cleared by `/scene off`. The status bar should answer *"which scene am I in"* — not display tool internals.
97
99
 
100
+ The prefix is customizable per scene via the `icon` field — emoji works great (`💻 coding`). The scaffolded presets ship with `💻 📄 🎯 🔍 📝 📊`, and the picker plus `/scene status` display the same icon; unset scenes fall back to `◆`.
101
+
98
102
  Scenes often bundle tool-heavy extensions whose own footer output crowds the bar. If you use the preset `coding` scene, pi-lens's diagnostics widget and `LSP Inactive` status can be silenced **without losing any AI-side value** (turn-end error injection, `lens_diagnostics`, symbol navigation) via `~/.pi-lens/config.json`:
99
103
 
100
104
  ```json
@@ -135,6 +139,8 @@ Usage data: `~/.pi/agent/scenes-usage.json` (machine-local, inert). View anytime
135
139
 
136
140
  In short: **installed forever, loaded per scene**. One caveat: extensions you installed manually (your own entries in settings) are yours — pi-scenes treats them as `borrowed`, never touches them, so they stay loaded in *every* scene.
137
141
 
142
+ **Package updates are scene-independent.** Every package — whichever scene lists it — is installed once, globally, under `~/.pi/agent/npm/`; scenes only flip the `settings.json` switch. So `pi update --extensions` works no matter which scene is active (pi's update banner scans installed packages, not the active scene), and since scene definitions use version-less specs (`npm:<pkg>`), the new version loads on the next switch/reload. One caveat: `0.x` caret ranges don't cross minor versions — if the banner persists after updating, pin it explicitly: `pi install npm:<pkg>@<version>`.
143
+
138
144
  ### Duplicate & conflict handling
139
145
 
140
146
  - Same spec in `common` and a scene → deduplicated at the union (loaded once).
@@ -166,6 +172,7 @@ In short: **installed forever, loaded per scene**. One caveat: extensions you in
166
172
  |---|---|
167
173
  | `common.packages` / `common.skills` | common-layer resources, always loaded |
168
174
  | `scenes.<name>.packages` | accepts `"npm:<pkg>"`, `"git:github.com/u/r"`, local paths, and object form (resource filtering, same grammar as pi settings) |
175
+ | `scenes.<name>.icon` | status-bar badge & picker prefix (emoji recommended; default `◆`) |
169
176
  | `scenes.<name>.skills` | paths/directories, `~` expanded |
170
177
  | `scenes.<name>.extends` | 🧪 inherit a parent scene (union merge + cycle detection) — forward-compatible entry for parent→child hierarchies |
171
178
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | self-evolution tunables (see "Self-evolution") |
@@ -183,7 +190,7 @@ Before uninstalling, `/scene off` and prune entries you don't want to keep from
183
190
 
184
191
  ```bash
185
192
  git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
186
- npm test # node:test, 18 cases: injection/reclaim + usage/evolution + conflict guards + command-layer smoke (no TUI needed)
193
+ npm test # node:test, 20 cases: injection/reclaim + usage/evolution + conflict guards + command-layer smoke (no TUI needed)
187
194
  ```
188
195
 
189
196
  Tests isolate via the `PI_SCENES_DIR` env var — your real `~/.pi/agent` is never touched.
@@ -213,6 +220,7 @@ pi 的 `packages` / `skills` 是全局平铺的:所有已安装扩展、所有
213
220
  - **通用层**:任何场景下恒加载的 extension + skill(如配额显示、会话延续)
214
221
  - **场景层**:每个场景自己的一组 extension + skill,激活才加载
215
222
  - 切换 = 改写 `settings.json` 的 `packages`/`skills` → `ctx.reload()` 热重载,**无需重启 pi**
223
+ - 每次切换成功后状态栏常驻**场景徽标**(`◆ coding`,或每场景自定义 `icon` 如 `💻 coding`),状态栏随时回答「我现在在哪个场景」——会话启动自动恢复,`/scene off` 清除
216
224
  - 数据模型预留 `extends` 继承链(带环检测),为将来「主场景 → 子场景」层级铺路
217
225
 
218
226
  ## 安装
@@ -268,6 +276,7 @@ pi install git:github.com/Feng-H/pi-scenes
268
276
  "scenes": { // ── 场景层:激活才叠加
269
277
  "coding": {
270
278
  "description": "写代码",
279
+ "icon": "💻",
271
280
  "packages": ["npm:pi-carryover"],
272
281
  "skills": ["~/.pi/agent/scenes/coding/skills"]
273
282
  },
@@ -289,6 +298,8 @@ pi install git:github.com/Feng-H/pi-scenes
289
298
 
290
299
  切换成功后状态栏常驻徽标(`◆ coding`),每次会话启动自动恢复,`/scene off` 清除。状态栏应该回答「我现在在哪个场景」——而不是展示工具的内部状态。
291
300
 
301
+ 徽标前缀可按场景用 `icon` 字段定制——emoji 完全可用(`💻 coding`)。脚手架预设自带 `💻 📄 🎯 🔍 📝 📊`,选择器与 `/scene status` 同步显示同一 icon;未配置的场景回退 `◆`。
302
+
292
303
  场景常打包工具型扩展,它们自己的 footer 输出会把状态栏拼得很吵。若使用预设 `coding` 场景,pi-lens 的诊断 widget 与 `LSP Inactive` 状态可在**不损失任何 AI 侧价值**(turn-end 错误注入、`lens_diagnostics`、符号导航)的前提下静音,写入 `~/.pi-lens/config.json`:
293
304
 
294
305
  ```json
@@ -329,6 +340,8 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
329
340
 
330
341
  一句话:**永远安装,只按场景加载**。注意:你手工 `pi install` 的条目属于你自己——pi-scenes 视为 `borrowed`,永不触碰,因此在**所有**场景都保持加载。
331
342
 
343
+ **包更新与场景无关。** 无论包被哪个场景引用,都只在全局安装一份(`~/.pi/agent/npm/`),场景只是拨动 `settings.json` 里的开关。因此 `pi update --extensions` 与当前在哪个场景无关(pi 的更新提示扫的是已安装包,不是活跃场景),且场景定义写的是不带版本的 `npm:<pkg>`,更新后下次切换/重载自动加载新版。注意 `0.x` 的 caret 范围不跨 minor——若更新提示反复出现,显式装指定版本:`pi install npm:<pkg>@<版本>`。
344
+
332
345
  ### 重复与冲突处理
333
346
 
334
347
  - 同一写法在 common 与场景重复 → 并集时去重,只加载一次。
@@ -360,6 +373,7 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
360
373
  |---|---|
361
374
  | `common.packages` / `common.skills` | 通用层资源,恒加载 |
362
375
  | `scenes.<name>.packages` | 支持 `"npm:<pkg>"`、`"git:github.com/u/r"`、本地路径字符串,及 object form(资源过滤,同 pi settings 规范) |
376
+ | `scenes.<name>.icon` | 状态栏徽标与选择器前缀(建议 emoji;缺省 `◆`) |
363
377
  | `scenes.<name>.skills` | 路径/目录数组,支持 `~` 展开 |
364
378
  | `scenes.<name>.extends` | 🧪 继承父场景(union 合并,带环检测)——「主场景→子场景」层级的前向兼容入口 |
365
379
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | 自进化阈值(见「自进化」节) |
@@ -377,7 +391,7 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
377
391
 
378
392
  ```bash
379
393
  git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
380
- npm test # node:test,18 用例:注入/回收 + 用量/进化 + 异写法冲突防护 + command 层冒烟(无需 TUI)
394
+ npm test # node:test,20 用例:注入/回收 + 用量/进化 + 异写法冲突防护 + command 层冒烟(无需 TUI)
381
395
  ```
382
396
 
383
397
  测试用 `PI_SCENES_DIR` 环境变量隔离基目录,不碰真实 `~/.pi/agent`。
@@ -57,6 +57,8 @@ export type PackageEntry = string | { source: string; [k: string]: unknown };
57
57
 
58
58
  export interface SceneDef {
59
59
  description?: string;
60
+ /** 状态栏徽标与选择器里的场景前缀(建议 emoji,如 💻);缺省 ◆ */
61
+ icon?: string;
60
62
  /** 前向兼容:继承父场景(主场景→子场景层级),资源按链 union 合并 */
61
63
  extends?: string;
62
64
  packages?: PackageEntry[];
@@ -775,6 +777,7 @@ export function makeCore(baseDir: string) {
775
777
  scenes: {
776
778
  coding: {
777
779
  description: "写代码:实时代码反馈、子代理委派、并行分支",
780
+ icon: "💻",
778
781
  packages: [
779
782
  "npm:pi-lens", // LSP/linter/格式化实时代码反馈
780
783
  "npm:pi-subagents", // 单代理委派 + 脚本化多代理工作流
@@ -784,6 +787,7 @@ export function makeCore(baseDir: string) {
784
787
  },
785
788
  office: {
786
789
  description: "办公:文档处理与日常事务",
790
+ icon: "📄",
787
791
  packages: [
788
792
  "npm:pi-docparser", // PDF/Office 文档解析抽取
789
793
  ],
@@ -791,6 +795,7 @@ export function makeCore(baseDir: string) {
791
795
  },
792
796
  pm: {
793
797
  description: "产品经理:竞品调研、目标规划与需求跟踪",
798
+ icon: "🎯",
794
799
  packages: [
795
800
  "npm:pi-web-access", // 网页搜索/抓取/PDF/YouTube(竞品与市场调研)
796
801
  "npm:pi-goal-x", // /goal 目标规划 + 独立完成度审计(roadmap/需求跟踪)
@@ -800,6 +805,7 @@ export function makeCore(baseDir: string) {
800
805
  },
801
806
  research: {
802
807
  description: "咨询调研:多源检索、并行多角度深挖",
808
+ icon: "🔍",
803
809
  packages: [
804
810
  "npm:pi-web-access", // 搜索/URL 抓取/PDF/视频理解(调研核心)
805
811
  "npm:pi-subagents", // 多角度并行调研(每个子代理一源)
@@ -808,6 +814,7 @@ export function makeCore(baseDir: string) {
808
814
  },
809
815
  writing: {
810
816
  description: "写作:素材检索、事实核查、文体打磨",
817
+ icon: "📝",
811
818
  packages: [
812
819
  "npm:pi-web-access", // 素材检索与事实核查(引用溯源)
813
820
  ],
@@ -815,6 +822,7 @@ export function makeCore(baseDir: string) {
815
822
  },
816
823
  data: {
817
824
  description: "数据分析:表格抽取、MCP 接数据库/BI",
825
+ icon: "📊",
818
826
  packages: [
819
827
  "npm:pi-docparser", // Excel/CSV/PDF 表格结构化抽取
820
828
  "npm:pi-mcp-adapter", // 接任意 MCP server(数据库/BI/内部数据服务)
@@ -871,7 +879,8 @@ export default function (pi: ExtensionAPI) {
871
879
  const core = makeCore(baseDir);
872
880
 
873
881
  /**
874
- * 状态栏常驻场景徽标(◆ <场景名>):切换后用户始终知道自己在哪个场景。
882
+ * 状态栏常驻场景徽标(<icon> <场景名>):切换后用户始终知道自己在哪个场景。
883
+ * 前缀可由 scenes.json 每场景 icon 字段定制(建议 emoji),缺省 ◆。
875
884
  * 设计动机:场景切换器在界面上只弹一次 notify 就消失了,用户无从得知当前场景;
876
885
  * 而场景附带的工具型扩展(如 pi-lens)的状态栏内脏反而在抢占视觉 ——
877
886
  * 状态栏应该回答“我在哪”,而不是“工具的内部状态”。
@@ -883,7 +892,8 @@ export default function (pi: ExtensionAPI) {
883
892
  if (!ui || typeof ui.setStatus !== "function") return;
884
893
  const active = core.loadState().active;
885
894
  if (active) {
886
- const text = `◆ ${active}`;
895
+ const icon = core.loadScenes().scenes?.[active]?.icon?.trim() || "◆";
896
+ const text = `${icon} ${active}`;
887
897
  ui.setStatus("pi-scene", ui.theme?.fg ? ui.theme.fg("accent", text) : text);
888
898
  } else {
889
899
  ui.setStatus("pi-scene", undefined);
@@ -1003,7 +1013,7 @@ export default function (pi: ExtensionAPI) {
1003
1013
  const target = core.computeTarget(st.active, cfg);
1004
1014
  const collisions = core.findSpecCollisions(cfg);
1005
1015
  const lines = [
1006
- `当前场景:${st.active ? st.active : "(无,仅通用层)"}`,
1016
+ `当前场景:${st.active ? `${cfg.scenes?.[st.active]?.icon?.trim() || "◆"} ${st.active}` : "(无,仅通用层)"}`,
1007
1017
  `生效 packages(${target.packages.length}):${target.packages.map(specOf).join(", ") || "—"}`,
1008
1018
  `生效 skills(${target.skills.length}):${target.skills.join(", ") || "—"}`,
1009
1019
  `可用场景:${Object.keys(cfg.scenes ?? {}).join(", ") || "—"}`,
@@ -1056,10 +1066,15 @@ export default function (pi: ExtensionAPI) {
1056
1066
  ctx.ui.notify(`scenes.json 里还没有定义场景,编辑 ${core.paths.scenesFile}`, "info");
1057
1067
  return;
1058
1068
  }
1069
+ // 选择器条目同步显示场景 icon(label→name 映射解析,免字符串切片)
1070
+ const labelToName = new Map<string, string>();
1059
1071
  const items: string[] = names.map((n) => {
1060
1072
  const d = cfg.scenes![n]?.description ?? "";
1073
+ const icon = cfg.scenes![n]?.icon?.trim() || "◆";
1061
1074
  const cur = st.active === n ? "●" : "○";
1062
- return `${cur} ${n}${d ? ` · ${d}` : ""}${st.active === n ? " [当前]" : ""}`;
1075
+ const label = `${cur} ${icon} ${n}${d ? ` · ${d}` : ""}${st.active === n ? " [当前]" : ""}`;
1076
+ labelToName.set(label, n);
1077
+ return label;
1063
1078
  });
1064
1079
  const extra = [PICKER_OFF + (st.active === null ? " [当前]" : ""), PICKER_CANCEL];
1065
1080
  const choice = await ctx.ui.select(`切换场景(通用层恒生效)`, [...items, ...extra]);
@@ -1072,8 +1087,9 @@ export default function (pi: ExtensionAPI) {
1072
1087
  await doSwitch(ctx, null);
1073
1088
  return;
1074
1089
  }
1075
- // "● name · desc" → name
1076
- const name = choice.slice(2).split(" ·")[0].split(" [")[0].trim();
1090
+ // label → 场景名(含 icon/描述的完整条目作为 key,避免解析歧义)
1091
+ const name = labelToName.get(choice);
1092
+ if (!name) return;
1077
1093
  if (st.active === name) {
1078
1094
  ctx.ui.notify(`当前已在场景「${name}」`, "info");
1079
1095
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-scenes",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "pi 扩展:场景切换器 + 资源自进化。通用层+分场景层打包 extension/skill,/scene 热切换;按实际用量(工具调用归因 + 会话结束 LLM 反思)生成吸收/淘汰提案,让场景定义随使用习惯进化。",
5
5
  "keywords": [
6
6
  "pi-package"