pi-scenes 0.2.1 → 0.3.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 +28 -2
- package/extensions/scenes.ts +25 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,18 @@ Edit it to fit your setup (each scene also gets a skill dir scaffold at `~/.pi/a
|
|
|
91
91
|
|
|
92
92
|
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
93
|
|
|
94
|
+
### Status-bar scene badge
|
|
95
|
+
|
|
96
|
+
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
|
+
|
|
98
|
+
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
|
+
|
|
100
|
+
```json
|
|
101
|
+
{ "ui": { "hideLspStatus": true }, "widget": { "visible": false } }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
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.
|
|
105
|
+
|
|
94
106
|
## Self-evolution (usage-driven)
|
|
95
107
|
|
|
96
108
|
Scenes are not static. pi-scenes observes what you actually use and proposes updates:
|
|
@@ -128,6 +140,7 @@ In short: **installed forever, loaded per scene**. One caveat: extensions you in
|
|
|
128
140
|
- Same spec in `common` and a scene → deduplicated at the union (loaded once).
|
|
129
141
|
- Same package, different spellings (e.g. `npm:x@1.0.3` vs bare `npm:x`) → identity-level dedupe keeps the first (common > scene); a manually pinned variant in settings is treated as `borrowed` (no duplicate injection). `/scene` and `/scene status` warn about such spelling mismatches so you can unify them.
|
|
130
142
|
- **Local path vs npm spelling (v0.2.1):** if settings already loads a package via a local path (e.g. your dev checkout `/Users/you/dev/pi-carryover`), a scene preset listing `npm:pi-carryover` will *borrow* your entry instead of installing — `pi install` is skipped so a second spelling is never appended to settings. This matters because two spellings of one package = the same extension loaded twice = pi exits at startup with a tool-name conflict. If settings ever ends up in that state (e.g. a manual `pi install` added the duplicate), `/scene` refuses to switch and tells you exactly which entries to delete.
|
|
143
|
+
- **Hotfix (v0.2.2):** `/scene <name>` crashed with `Extension "command:scene" error: target.filter is not a function` — the v0.2.1 refactor passed `computeTarget()`'s `{packages, skills}` object where the old call site used `target.packages`. Any scene switch hit this. Fixed, plus a command-layer smoke test (isolated via `PI_SCENES_DIR` + dynamic import in a dedicated test file, because the extension's default export resolves its base dir at module-evaluation time — a static import in tests would read/write your real `~/.pi/agent`).
|
|
131
144
|
|
|
132
145
|
## How it works
|
|
133
146
|
|
|
@@ -170,7 +183,7 @@ Before uninstalling, `/scene off` and prune entries you don't want to keep from
|
|
|
170
183
|
|
|
171
184
|
```bash
|
|
172
185
|
git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
|
|
173
|
-
npm test # node:test,
|
|
186
|
+
npm test # node:test, 18 cases: injection/reclaim + usage/evolution + conflict guards + command-layer smoke (no TUI needed)
|
|
174
187
|
```
|
|
175
188
|
|
|
176
189
|
Tests isolate via the `PI_SCENES_DIR` env var — your real `~/.pi/agent` is never touched.
|
|
@@ -272,6 +285,18 @@ pi install git:github.com/Feng-H/pi-scenes
|
|
|
272
285
|
场景 skill 目录里放 `SKILL.md` 文件夹(或 `.md` 文件)即可,切换场景时整目录启停。
|
|
273
286
|
`/scene init` 会创建 `~/.pi/agent/scenes/{common,coding,office,pm,research,writing,data}/skills/` 骨架。
|
|
274
287
|
|
|
288
|
+
### 状态栏场景徽标
|
|
289
|
+
|
|
290
|
+
切换成功后状态栏常驻徽标(`◆ coding`),每次会话启动自动恢复,`/scene off` 清除。状态栏应该回答「我现在在哪个场景」——而不是展示工具的内部状态。
|
|
291
|
+
|
|
292
|
+
场景常打包工具型扩展,它们自己的 footer 输出会把状态栏拼得很吵。若使用预设 `coding` 场景,pi-lens 的诊断 widget 与 `LSP Inactive` 状态可在**不损失任何 AI 侧价值**(turn-end 错误注入、`lens_diagnostics`、符号导航)的前提下静音,写入 `~/.pi-lens/config.json`:
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{ "ui": { "hideLspStatus": true }, "widget": { "visible": false } }
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏上的唯一东西。
|
|
299
|
+
|
|
275
300
|
## 自进化(用量驱动)
|
|
276
301
|
|
|
277
302
|
场景不是静态的。pi-scenes 观察你的实际使用并提议更新:
|
|
@@ -309,6 +334,7 @@ pi install git:github.com/Feng-H/pi-scenes
|
|
|
309
334
|
- 同一写法在 common 与场景重复 → 并集时去重,只加载一次。
|
|
310
335
|
- 同包异写法(如 `npm:x@1.0.3` 与裸名 `npm:x`)→ 身份级去重取首个(common 优先);settings 里手动 pin 的异写法条目视为 `borrowed`,不重复注入。`/scene` 切换与 `/scene status` 会对异写法发出提醒,建议统一。
|
|
311
336
|
- **本地路径与 npm 写法并存(v0.2.1):** 若 settings 已通过本地路径加载某包(如你的开发目录 `/Users/you/dev/pi-carryover`),场景预设里的 `npm:pi-carryover` 会*借用*你的条目而不安装——跳过 `pi install`,绝不向 settings 追加第二种写法。这一点很关键:同一包双写法 = 同一扩展被加载两份 = pi 启动时工具重名冲突退出。若 settings 已陷入该状态(如手动 `pi install` 造成的重复),`/scene` 会拒绝切换并明确告知需要删除哪个条目。
|
|
337
|
+
- **热修(v0.2.2):** `/scene <name>` 曾报 `Extension "command:scene" error: target.filter is not a function`——v0.2.1 重构时把 `computeTarget()` 返回的 `{packages, skills}` 对象传给了旧调用点用 `target.packages` 的地方,任何场景切换必触发。已修复,并补 command 层冒烟测试(独立测试文件 + `PI_SCENES_DIR` 环境变量 + 动态 import 隔离:扩展 default export 在模块求值时解析 base 目录,测试里静态 import 会直接读写真实 `~/.pi/agent`)。
|
|
312
338
|
|
|
313
339
|
## 工作原理
|
|
314
340
|
|
|
@@ -351,7 +377,7 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
|
|
|
351
377
|
|
|
352
378
|
```bash
|
|
353
379
|
git clone https://github.com/Feng-H/pi-scenes && cd pi-scenes
|
|
354
|
-
npm test # node:test,
|
|
380
|
+
npm test # node:test,18 用例:注入/回收 + 用量/进化 + 异写法冲突防护 + command 层冒烟(无需 TUI)
|
|
355
381
|
```
|
|
356
382
|
|
|
357
383
|
测试用 `PI_SCENES_DIR` 环境变量隔离基目录,不碰真实 `~/.pi/agent`。
|
package/extensions/scenes.ts
CHANGED
|
@@ -870,6 +870,27 @@ export default function (pi: ExtensionAPI) {
|
|
|
870
870
|
const baseDir = process.env.PI_SCENES_DIR || path.join(os.homedir(), ".pi", "agent");
|
|
871
871
|
const core = makeCore(baseDir);
|
|
872
872
|
|
|
873
|
+
/**
|
|
874
|
+
* 状态栏常驻场景徽标(◆ <场景名>):切换后用户始终知道自己在哪个场景。
|
|
875
|
+
* 设计动机:场景切换器在界面上只弹一次 notify 就消失了,用户无从得知当前场景;
|
|
876
|
+
* 而场景附带的工具型扩展(如 pi-lens)的状态栏内脏反而在抢占视觉 ——
|
|
877
|
+
* 状态栏应该回答“我在哪”,而不是“工具的内部状态”。
|
|
878
|
+
* off(仅通用层)时清除;session_start 时幂等重放(重启 pi 后恢复)。
|
|
879
|
+
*/
|
|
880
|
+
function updateSceneBadge(ctx: any): void {
|
|
881
|
+
try {
|
|
882
|
+
const ui = ctx?.ui;
|
|
883
|
+
if (!ui || typeof ui.setStatus !== "function") return;
|
|
884
|
+
const active = core.loadState().active;
|
|
885
|
+
if (active) {
|
|
886
|
+
const text = `◆ ${active}`;
|
|
887
|
+
ui.setStatus("pi-scene", ui.theme?.fg ? ui.theme.fg("accent", text) : text);
|
|
888
|
+
} else {
|
|
889
|
+
ui.setStatus("pi-scene", undefined);
|
|
890
|
+
}
|
|
891
|
+
} catch {}
|
|
892
|
+
}
|
|
893
|
+
|
|
873
894
|
/** 执行切换(name=null 表示仅通用层) */
|
|
874
895
|
async function doSwitch(ctx: any, name: string | null): Promise<void> {
|
|
875
896
|
const cfg = core.loadScenes();
|
|
@@ -910,7 +931,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
910
931
|
// 缺失包:确认后逐个 pi install(全局 scope pi 不自动装,必须显式装)
|
|
911
932
|
// 身份级判定:settings 已手配同包异写法(如本地路径)→ 视为可用,跳过安装;
|
|
912
933
|
// 否则 pi install 会向 settings 追加第二种写法 → 同一扩展加载两份 → pi 启动冲突退出
|
|
913
|
-
const missing = core.findMissingPackages(target, prePkgs);
|
|
934
|
+
const missing = core.findMissingPackages(target.packages, prePkgs);
|
|
914
935
|
let preInstallPackages: PackageEntry[] | undefined;
|
|
915
936
|
if (missing.length > 0) {
|
|
916
937
|
const ok = await ctx.ui.confirm(
|
|
@@ -930,7 +951,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
930
951
|
}
|
|
931
952
|
}
|
|
932
953
|
const postPkgs = (readJson<Record<string, unknown>>(core.paths.settingsFile, {}).packages ?? []) as PackageEntry[];
|
|
933
|
-
|
|
954
|
+
const still = core.findMissingPackages(target.packages, postPkgs);
|
|
934
955
|
if (still.length > 0) {
|
|
935
956
|
ctx.ui.notify(`仍有包未安装:${still.map(specOf).join(", ")},已中止切换`, "error");
|
|
936
957
|
return;
|
|
@@ -938,6 +959,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
938
959
|
}
|
|
939
960
|
|
|
940
961
|
const r = core.applyToSettings(target, name, preInstallPackages);
|
|
962
|
+
updateSceneBadge(ctx);
|
|
941
963
|
ctx.ui.notify(
|
|
942
964
|
`已切换到 ${label}\n +${r.addedPackages.length} 包 +${r.addedSkills.length} skill · -${r.removedPackages.length} 包 -${r.removedSkills.length} skill\n 正在热重载…`,
|
|
943
965
|
"info",
|
|
@@ -1215,6 +1237,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1215
1237
|
const pkgs = readJson<Record<string, unknown>>(core.paths.settingsFile, {}).packages;
|
|
1216
1238
|
core.beginSession(ctx.sessionManager?.getSessionFile?.() ?? null, Array.isArray(pkgs) ? (pkgs as PackageEntry[]) : []);
|
|
1217
1239
|
} catch {}
|
|
1240
|
+
updateSceneBadge(ctx);
|
|
1218
1241
|
});
|
|
1219
1242
|
|
|
1220
1243
|
pi.on("tool_call", async (event) => {
|