pi-scenes 0.2.2 → 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
  },
@@ -91,6 +93,20 @@ Edit it to fit your setup (each scene also gets a skill dir scaffold at `~/.pi/a
91
93
 
92
94
  Drop `SKILL.md` folders (or `.md` files) into a scene's skill directory; the whole directory toggles with the scene. `/scene init` scaffolds `~/.pi/agent/scenes/{common,coding,office,pm,research,writing,data}/skills/`.
93
95
 
96
+ ### Status-bar scene badge
97
+
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.
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
+
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`:
103
+
104
+ ```json
105
+ { "ui": { "hideLspStatus": true }, "widget": { "visible": false } }
106
+ ```
107
+
108
+ pi-scenes never edits a third-party package's global config — the badge stays the only thing pi-scenes itself puts on your status bar.
109
+
94
110
  ## Self-evolution (usage-driven)
95
111
 
96
112
  Scenes are not static. pi-scenes observes what you actually use and proposes updates:
@@ -123,6 +139,8 @@ Usage data: `~/.pi/agent/scenes-usage.json` (machine-local, inert). View anytime
123
139
 
124
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.
125
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
+
126
144
  ### Duplicate & conflict handling
127
145
 
128
146
  - Same spec in `common` and a scene → deduplicated at the union (loaded once).
@@ -154,6 +172,7 @@ In short: **installed forever, loaded per scene**. One caveat: extensions you in
154
172
  |---|---|
155
173
  | `common.packages` / `common.skills` | common-layer resources, always loaded |
156
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 `◆`) |
157
176
  | `scenes.<name>.skills` | paths/directories, `~` expanded |
158
177
  | `scenes.<name>.extends` | 🧪 inherit a parent scene (union merge + cycle detection) — forward-compatible entry for parent→child hierarchies |
159
178
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | self-evolution tunables (see "Self-evolution") |
@@ -171,7 +190,7 @@ Before uninstalling, `/scene off` and prune entries you don't want to keep from
171
190
 
172
191
  ```bash
173
192
  git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
174
- 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)
175
194
  ```
176
195
 
177
196
  Tests isolate via the `PI_SCENES_DIR` env var — your real `~/.pi/agent` is never touched.
@@ -201,6 +220,7 @@ pi 的 `packages` / `skills` 是全局平铺的:所有已安装扩展、所有
201
220
  - **通用层**:任何场景下恒加载的 extension + skill(如配额显示、会话延续)
202
221
  - **场景层**:每个场景自己的一组 extension + skill,激活才加载
203
222
  - 切换 = 改写 `settings.json` 的 `packages`/`skills` → `ctx.reload()` 热重载,**无需重启 pi**
223
+ - 每次切换成功后状态栏常驻**场景徽标**(`◆ coding`,或每场景自定义 `icon` 如 `💻 coding`),状态栏随时回答「我现在在哪个场景」——会话启动自动恢复,`/scene off` 清除
204
224
  - 数据模型预留 `extends` 继承链(带环检测),为将来「主场景 → 子场景」层级铺路
205
225
 
206
226
  ## 安装
@@ -256,6 +276,7 @@ pi install git:github.com/Feng-H/pi-scenes
256
276
  "scenes": { // ── 场景层:激活才叠加
257
277
  "coding": {
258
278
  "description": "写代码",
279
+ "icon": "💻",
259
280
  "packages": ["npm:pi-carryover"],
260
281
  "skills": ["~/.pi/agent/scenes/coding/skills"]
261
282
  },
@@ -273,6 +294,20 @@ pi install git:github.com/Feng-H/pi-scenes
273
294
  场景 skill 目录里放 `SKILL.md` 文件夹(或 `.md` 文件)即可,切换场景时整目录启停。
274
295
  `/scene init` 会创建 `~/.pi/agent/scenes/{common,coding,office,pm,research,writing,data}/skills/` 骨架。
275
296
 
297
+ ### 状态栏场景徽标
298
+
299
+ 切换成功后状态栏常驻徽标(`◆ coding`),每次会话启动自动恢复,`/scene off` 清除。状态栏应该回答「我现在在哪个场景」——而不是展示工具的内部状态。
300
+
301
+ 徽标前缀可按场景用 `icon` 字段定制——emoji 完全可用(`💻 coding`)。脚手架预设自带 `💻 📄 🎯 🔍 📝 📊`,选择器与 `/scene status` 同步显示同一 icon;未配置的场景回退 `◆`。
302
+
303
+ 场景常打包工具型扩展,它们自己的 footer 输出会把状态栏拼得很吵。若使用预设 `coding` 场景,pi-lens 的诊断 widget 与 `LSP Inactive` 状态可在**不损失任何 AI 侧价值**(turn-end 错误注入、`lens_diagnostics`、符号导航)的前提下静音,写入 `~/.pi-lens/config.json`:
304
+
305
+ ```json
306
+ { "ui": { "hideLspStatus": true }, "widget": { "visible": false } }
307
+ ```
308
+
309
+ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏上的唯一东西。
310
+
276
311
  ## 自进化(用量驱动)
277
312
 
278
313
  场景不是静态的。pi-scenes 观察你的实际使用并提议更新:
@@ -305,6 +340,8 @@ pi install git:github.com/Feng-H/pi-scenes
305
340
 
306
341
  一句话:**永远安装,只按场景加载**。注意:你手工 `pi install` 的条目属于你自己——pi-scenes 视为 `borrowed`,永不触碰,因此在**所有**场景都保持加载。
307
342
 
343
+ **包更新与场景无关。** 无论包被哪个场景引用,都只在全局安装一份(`~/.pi/agent/npm/`),场景只是拨动 `settings.json` 里的开关。因此 `pi update --extensions` 与当前在哪个场景无关(pi 的更新提示扫的是已安装包,不是活跃场景),且场景定义写的是不带版本的 `npm:<pkg>`,更新后下次切换/重载自动加载新版。注意 `0.x` 的 caret 范围不跨 minor——若更新提示反复出现,显式装指定版本:`pi install npm:<pkg>@<版本>`。
344
+
308
345
  ### 重复与冲突处理
309
346
 
310
347
  - 同一写法在 common 与场景重复 → 并集时去重,只加载一次。
@@ -336,6 +373,7 @@ pi install git:github.com/Feng-H/pi-scenes
336
373
  |---|---|
337
374
  | `common.packages` / `common.skills` | 通用层资源,恒加载 |
338
375
  | `scenes.<name>.packages` | 支持 `"npm:<pkg>"`、`"git:github.com/u/r"`、本地路径字符串,及 object form(资源过滤,同 pi settings 规范) |
376
+ | `scenes.<name>.icon` | 状态栏徽标与选择器前缀(建议 emoji;缺省 `◆`) |
339
377
  | `scenes.<name>.skills` | 路径/目录数组,支持 `~` 展开 |
340
378
  | `scenes.<name>.extends` | 🧪 继承父场景(union 合并,带环检测)——「主场景→子场景」层级的前向兼容入口 |
341
379
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | 自进化阈值(见「自进化」节) |
@@ -353,7 +391,7 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
353
391
 
354
392
  ```bash
355
393
  git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
356
- npm test # node:test,18 用例:注入/回收 + 用量/进化 + 异写法冲突防护 + command 层冒烟(无需 TUI)
394
+ npm test # node:test,20 用例:注入/回收 + 用量/进化 + 异写法冲突防护 + command 层冒烟(无需 TUI)
357
395
  ```
358
396
 
359
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/内部数据服务)
@@ -870,6 +878,29 @@ export default function (pi: ExtensionAPI) {
870
878
  const baseDir = process.env.PI_SCENES_DIR || path.join(os.homedir(), ".pi", "agent");
871
879
  const core = makeCore(baseDir);
872
880
 
881
+ /**
882
+ * 状态栏常驻场景徽标(<icon> <场景名>):切换后用户始终知道自己在哪个场景。
883
+ * 前缀可由 scenes.json 每场景 icon 字段定制(建议 emoji),缺省 ◆。
884
+ * 设计动机:场景切换器在界面上只弹一次 notify 就消失了,用户无从得知当前场景;
885
+ * 而场景附带的工具型扩展(如 pi-lens)的状态栏内脏反而在抢占视觉 ——
886
+ * 状态栏应该回答“我在哪”,而不是“工具的内部状态”。
887
+ * off(仅通用层)时清除;session_start 时幂等重放(重启 pi 后恢复)。
888
+ */
889
+ function updateSceneBadge(ctx: any): void {
890
+ try {
891
+ const ui = ctx?.ui;
892
+ if (!ui || typeof ui.setStatus !== "function") return;
893
+ const active = core.loadState().active;
894
+ if (active) {
895
+ const icon = core.loadScenes().scenes?.[active]?.icon?.trim() || "◆";
896
+ const text = `${icon} ${active}`;
897
+ ui.setStatus("pi-scene", ui.theme?.fg ? ui.theme.fg("accent", text) : text);
898
+ } else {
899
+ ui.setStatus("pi-scene", undefined);
900
+ }
901
+ } catch {}
902
+ }
903
+
873
904
  /** 执行切换(name=null 表示仅通用层) */
874
905
  async function doSwitch(ctx: any, name: string | null): Promise<void> {
875
906
  const cfg = core.loadScenes();
@@ -938,6 +969,7 @@ export default function (pi: ExtensionAPI) {
938
969
  }
939
970
 
940
971
  const r = core.applyToSettings(target, name, preInstallPackages);
972
+ updateSceneBadge(ctx);
941
973
  ctx.ui.notify(
942
974
  `已切换到 ${label}\n +${r.addedPackages.length} 包 +${r.addedSkills.length} skill · -${r.removedPackages.length} 包 -${r.removedSkills.length} skill\n 正在热重载…`,
943
975
  "info",
@@ -981,7 +1013,7 @@ export default function (pi: ExtensionAPI) {
981
1013
  const target = core.computeTarget(st.active, cfg);
982
1014
  const collisions = core.findSpecCollisions(cfg);
983
1015
  const lines = [
984
- `当前场景:${st.active ? st.active : "(无,仅通用层)"}`,
1016
+ `当前场景:${st.active ? `${cfg.scenes?.[st.active]?.icon?.trim() || "◆"} ${st.active}` : "(无,仅通用层)"}`,
985
1017
  `生效 packages(${target.packages.length}):${target.packages.map(specOf).join(", ") || "—"}`,
986
1018
  `生效 skills(${target.skills.length}):${target.skills.join(", ") || "—"}`,
987
1019
  `可用场景:${Object.keys(cfg.scenes ?? {}).join(", ") || "—"}`,
@@ -1034,10 +1066,15 @@ export default function (pi: ExtensionAPI) {
1034
1066
  ctx.ui.notify(`scenes.json 里还没有定义场景,编辑 ${core.paths.scenesFile}`, "info");
1035
1067
  return;
1036
1068
  }
1069
+ // 选择器条目同步显示场景 icon(label→name 映射解析,免字符串切片)
1070
+ const labelToName = new Map<string, string>();
1037
1071
  const items: string[] = names.map((n) => {
1038
1072
  const d = cfg.scenes![n]?.description ?? "";
1073
+ const icon = cfg.scenes![n]?.icon?.trim() || "◆";
1039
1074
  const cur = st.active === n ? "●" : "○";
1040
- 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;
1041
1078
  });
1042
1079
  const extra = [PICKER_OFF + (st.active === null ? " [当前]" : ""), PICKER_CANCEL];
1043
1080
  const choice = await ctx.ui.select(`切换场景(通用层恒生效)`, [...items, ...extra]);
@@ -1050,8 +1087,9 @@ export default function (pi: ExtensionAPI) {
1050
1087
  await doSwitch(ctx, null);
1051
1088
  return;
1052
1089
  }
1053
- // "● name · desc" → name
1054
- const name = choice.slice(2).split(" ·")[0].split(" [")[0].trim();
1090
+ // label → 场景名(含 icon/描述的完整条目作为 key,避免解析歧义)
1091
+ const name = labelToName.get(choice);
1092
+ if (!name) return;
1055
1093
  if (st.active === name) {
1056
1094
  ctx.ui.notify(`当前已在场景「${name}」`, "info");
1057
1095
  return;
@@ -1215,6 +1253,7 @@ export default function (pi: ExtensionAPI) {
1215
1253
  const pkgs = readJson<Record<string, unknown>>(core.paths.settingsFile, {}).packages;
1216
1254
  core.beginSession(ctx.sessionManager?.getSessionFile?.() ?? null, Array.isArray(pkgs) ? (pkgs as PackageEntry[]) : []);
1217
1255
  } catch {}
1256
+ updateSceneBadge(ctx);
1218
1257
  });
1219
1258
 
1220
1259
  pi.on("tool_call", async (event) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-scenes",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "pi 扩展:场景切换器 + 资源自进化。通用层+分场景层打包 extension/skill,/scene 热切换;按实际用量(工具调用归因 + 会话结束 LLM 反思)生成吸收/淘汰提案,让场景定义随使用习惯进化。",
5
5
  "keywords": [
6
6
  "pi-package"