pi-scenes 0.8.0 → 0.10.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
@@ -55,21 +55,23 @@ Then `/reload` and `/scene` is live.
55
55
  /scene migrate # convert a ≤0.6 legacy global scene into this project's scene
56
56
  /scene init # scaffold scenes.json template + scene skill dirs
57
57
  /scene stats # usage dashboard: sessions, tool calls, reflections
58
+ /scene update-assets # sync preset templates/skills from the package (edits kept, rest updated)
58
59
  /scene evolve # generate & apply evolution proposals (confirm-first)
59
60
  /scene evolve auto # toggle auto-apply at session end (opt-in)
60
61
  ```
61
62
 
62
- First run of `/scene` offers to generate the template. It ships with **seven preset scenes + common** — a curated best-practice collection (all packages verified on npm/GitHub, 2026-09). v0.6.0 upgrades the presets with a full skill layer: git skill bundles install per scene with object-form resource filters, and research/writing ship vendored starter skills:
63
+ First run of `/scene` offers to generate the template. It ships with **eight preset scenes + common** — a curated best-practice collection (all packages verified on npm/GitHub, 2026-09). v0.6.0 upgrades the presets with a full skill layer: git skill bundles install per scene with object-form resource filters, and research/writing ship vendored starter skills:
63
64
 
64
65
  | Scene | Extensions | Skills | Prompt templates (v0.8) |
65
66
  |---|---|---|---|
66
67
  | `common` | `npm:pi-scenes`, `npm:pi-carryover` | — (your own dir) | — |
67
- | `coding` | `npm:pi-lens`, `npm:pi-subagents`, `npm:pi-git-worktree`, `npm:pi-simplify` | `openclaw/agent-skills` → autoreview, handoff;`anthropics/skills` → frontend-design, webapp-testing, mcp-builder | `/pre-commit` |
68
+ | `coding` | `npm:pi-lens`, `npm:pi-subagents`, `npm:pi-git-worktree`, `npm:pi-simplify` | `anthropics/skills` → frontend-design, webapp-testing, mcp-builder | `/pre-commit` |
68
69
  | `office` | `npm:pi-docparser` | `anthropics/skills` → docx, pptx, xlsx, pdf, internal-comms | `/doc-from-notes` |
69
70
  | `pm` | `npm:pi-web-access`, `npm:pi-goal-x`, `npm:@juicesharp/rpiv-todo`, `npm:@juicesharp/rpiv-ask-user-question` | — | `/prd-skeleton` |
70
71
  | `research` | `npm:pi-web-access`, `npm:pi-subagents` | 预置:arxiv-research, openalex-paper-search | `/deep-dive` |
71
72
  | `writing` | `npm:pi-web-access` | `anthropics/skills` → doc-coauthoring;预置:humanizer | `/fact-check` |
72
73
  | `data` | `npm:pi-docparser`, `npm:pi-mcp-adapter` | — | `/data-audit` |
74
+ | `learning` | `npm:pi-web-access`, `npm:pi-subagents` | 预置:eli5 | `/feynman`, `/socratic`, `/flashcards` |
73
75
 
74
76
  Each preset template is a fixed procedure that forbids step-skipping (e.g. `/pre-commit` = build → test → diff review → commit message, each step ✅/❌ with evidence). After switching scenes, try the scene's template command directly; drop your own `.md` files into `~/.pi/agent/scenes/<name>/prompts/` to add more.
75
77
 
@@ -261,6 +263,27 @@ cp ~/.pi/agent/settings.json.scenes-bak ~/.pi/agent/settings.json # restore if
261
263
 
262
264
  Before uninstalling, `/scene off` and prune entries you don't want to keep from `packages`/`skills`. `scenes.json` / `scenes-state.json` / the `scenes/` tree are inert leftovers — safe to keep or delete.
263
265
 
266
+ ## Changelog
267
+
268
+ ### v0.10.0 (2026-09-23)
269
+
270
+ - **Vendored asset fingerprints + safe updates** — preset templates/skills copied to `~/.pi/agent/scenes/` now record a content-hash baseline (`.assets-manifest.json`). New `/scene update-assets` command syncs package assets to your disk: **untouched files follow new package versions; files you edited are kept yours** (listed as conflicts); presets removed from the package are reported but never auto-deleted. Closes the "npm updates don't update vendored assets" gap — ownership transfer no longer means losing updates
271
+ - Scaffold now runs the same safe sync internally (fills missing + records baselines)
272
+
273
+ ### v0.9.0 (2026-09-23)
274
+
275
+ - **New preset scene: `learning` 📚** (8th preset) — knowledge internalization, verification, and spaced review. Ships `pi-web-access` (learning materials) + `pi-subagents` (parallel multi-perspective study), three workflow templates (`/feynman` four-step internalization, `/socratic` question-only verification, `/flashcards` Q&A+cloze cards with a spaced-repetition schedule), and a vendored `eli5` skill (analogy-first, zero-jargon first pass, 5yo/12yo/adult three-tier explanations)
276
+ - **Preset fix: removed `openclaw/agent-skills` from coding** — verified as an OpenClaw-project-internal workflow library rather than general-purpose coding skills (autoreview hard-codes an OpenAI/Codex preference; handoff is a clipboard-prompt workflow). Its duties were already covered by `pi-simplify` / `pi-subagents`. Lesson recorded: existence verification ≠ positioning verification
277
+ - Full preset audit: 10 npm extensions, 9 anthropics/skills subsets, 3 vendored skills — all verified real and accurately described
278
+
279
+ ### v0.8.0 (2026-09-23)
280
+
281
+ - **Scene-scoped prompt templates** — `prompts` field per scene: scene = tools + skills + workflow templates as one unit. Injected via pi's `resources_discover` event: **zero settings writes, templates vanish when you switch away** (unlike packages/skills which land in settings.json)
282
+ - Same-name resolution: your hand-written templates and package templates win over scene presets — user intent beats presets
283
+ - Six preset workflow templates (`/pre-commit`, `/deep-dive`, `/fact-check`, `/prd-skeleton`, `/doc-from-notes`, `/data-audit`), each an explicit step-by-step checklist the model cannot skip
284
+ - Scaffold creates `prompts/` directory skeletons and vendors preset templates idempotently (never overwrites your edits); `/scene status` shows effective templates; switch notification counts template dirs
285
+ - Backward compatible: existing scenes.json without `prompts` behaves exactly as v0.7
286
+
264
287
  ## Development
265
288
 
266
289
  ```bash
@@ -330,11 +353,12 @@ pi install git:github.com/Feng-H/pi-scenes
330
353
  /scene migrate # 把 ≤0.6 遗留的全局场景转为当前项目场景
331
354
  /scene init # 生成模板 scenes.json + 场景 skill 目录骨架
332
355
  /scene stats # 用量仪表盘:会话数 / 工具调用 / 反思评分
356
+ /scene update-assets # 同步包内预置模板/skill(未修改跟随新版,改过的保留)
333
357
  /scene evolve # 生成并应用进化提案(逐条确认)
334
358
  /scene evolve auto # 开关:会话结束自动应用(opt-in)
335
359
  ```
336
360
 
337
- 首次运行 `/scene` 会询问是否生成模板,生成后编辑场景定义。模板内置 **七个预设场景 + 通用层**(包均在 npm 核验存在,2026-09):
361
+ 首次运行 `/scene` 会询问是否生成模板,生成后编辑场景定义。模板内置 **八个预设场景 + 通用层**(包均在 npm 核验存在,2026-09):
338
362
 
339
363
  | 层 | 预设 packages | 理由 |
340
364
  |---|---|---|
@@ -345,8 +369,9 @@ pi install git:github.com/Feng-H/pi-scenes
345
369
  | `research` | `npm:pi-web-access`、`npm:pi-subagents` | 多源搜索/抓取/PDF/视频,并行多角度深挖 |
346
370
  | `writing` | `npm:pi-web-access` | 素材检索与事实核查(引用溯源) |
347
371
  | `data` | `npm:pi-docparser`、`npm:pi-mcp-adapter` | 表格结构化抽取、接任意 MCP server(数据库/BI) |
372
+ | `learning` | `npm:pi-web-access`、`npm:pi-subagents` | 学习材料获取、并行多视角学习;预置 skill:eli5(大白话解释) |
348
373
 
349
- v0.8 起每个预设场景还携带一个流程模板(coding→`/pre-commit`、office→`/doc-from-notes`、pm→`/prd-skeleton`、research→`/deep-dive`、writing→`/fact-check`、data→`/data-audit`),切换后直接可用;自己加模板只需往 `~/.pi/agent/scenes/<名>/prompts/` 丢 `.md` 文件。
374
+ v0.8 起每个预设场景还携带流程模板(coding→`/pre-commit`、office→`/doc-from-notes`、pm→`/prd-skeleton`、research→`/deep-dive`、writing→`/fact-check`、data→`/data-audit`;v0.9 learning 场景→`/feynman` 费曼内化 + `/socratic` 苏格拉底检验 + `/flashcards` 闪卡复习,三件套),切换后直接可用;自己加模板只需往 `~/.pi/agent/scenes/<名>/prompts/` 丢 `.md` 文件。
350
375
 
351
376
  每个场景同时生成 skill / prompts 目录骨架 `~/.pi/agent/scenes/<名>/{skills,prompts}/`,按需编辑:
352
377
 
@@ -529,6 +554,27 @@ cp ~/.pi/agent/settings.json.scenes-bak ~/.pi/agent/settings.json # 如需恢
529
554
 
530
555
  managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packages`/`skills` 里不想保留的条目;`scenes.json` / `scenes-state.json` / `scenes/` 目录留着不影响 pi 运行。
531
556
 
557
+ ## 版本历史
558
+
559
+ ### v0.10.0(2026-09-23)
560
+
561
+ - **vendored 资产指纹 + 安全更新**——预置模板/skill 复制到 `~/.pi/agent/scenes/` 时记录内容指纹基线(`.assets-manifest.json`)。新增 `/scene update-assets` 命令同步包内资产到落盘:**你未修改的跟随包新版,你改过的保留你的版本**(列为冲突清单),包内已删除的预设仅提示不自动删。补上「npm 更新不更新 vendored 资产」的缺口——所有权移交不再等于更新断绝
562
+ - scaffold 内部改走同一套安全同步(补缺失 + 记基线)
563
+
564
+ ### v0.9.0(2026-09-23)
565
+
566
+ - **新增预设场景 `learning` 📚**(第八个)——知识内化、检验、间隔复习。携带 `pi-web-access`(学习材料)+ `pi-subagents`(并行多视角学习)、三个流程模板(`/feynman` 费曼四步内化、`/socratic` 只问不讲的苏格拉底检验、`/flashcards` Q&A+填空双卡型配间隔复习排程)、vendored 技能 `eli5`(类比先行、零术语首过、5 岁/12 岁/成人三档递进)
567
+ - **预设修正:coding 场景移除 `openclaw/agent-skills`**(随本版发布)——核验其为 OpenClaw 项目内部工作流库而非通用编码技能(autoreview 硬编码 OpenAI/Codex 偏好;handoff 是剪贴板提示词流程),其职责已由 `pi-simplify` / `pi-subagents` 覆盖。教训:存在核验 ≠ 定位核验
568
+ - 全预设体检:npm 扩展×10、anthropics/skills 子集×9、vendored×3,全部真实存在且描述如述
569
+
570
+ ### v0.8.0(2026-09-23)
571
+
572
+ - **场景化 prompt 模板**——场景新增 `prompts` 字段:场景成为工具+技能+流程模板三位一体。注入走 pi 的 `resources_discover` 事件:**零 settings 写入、切走模板自动消失**(与落 settings.json 的 packages/skills 不同路径)
573
+ - 同名解析:用户手写模板与包模板优先于场景预设——用户意图压过预设
574
+ - 六个预置流程模板(`/pre-commit` 提交自检、`/deep-dive` 深度调研、`/fact-check` 事实核查、`/prd-skeleton` 需求骨架、`/doc-from-notes` 笔记成文、`/data-audit` 数据审计),每个都是显式步骤清单、模型无法跳步
575
+ - scaffold 生成 `prompts/` 目录骨架 + 预置模板 vendored 幂等复制(不覆盖你的修改);`/scene status` 显示生效模板;切换通知带模板目录计数
576
+ - 向后兼容:存量 scenes.json 无 `prompts` 字段时行为与 v0.7 完全一致
577
+
532
578
  ## 开发
533
579
 
534
580
  ```bash
@@ -0,0 +1,16 @@
1
+ ---
2
+ description: 费曼学习法四步——用大白话讲出来,卡壳处即知识缺口
3
+ argument-hint: "<要学习的概念>"
4
+ ---
5
+ 用费曼学习法帮我内化以下概念:$@
6
+
7
+ **铁律:用大白话,禁止照搬术语解释术语;卡壳 = 找到了缺口,是收获不是失败。**
8
+
9
+ 四步循环:
10
+
11
+ 1. **选概念**:把「$@」拆成 2-4 个子概念,确认我的现有理解水平(先问我或让我先说)。
12
+ 2. **讲解**:让我用自己的话解释每个子概念(或你先示范一段大白话讲解,再让我复述)。
13
+ 3. **找卡点**:我讲不清、绕圈子、或你追问三连(为什么?举个例子?反过来会怎样?)答不上的地方,逐个标记为缺口。
14
+ 4. **回源补漏**:每个缺口回到原始材料(文档/教程/代码)定向补学,然后**重新讲解验证**,直到全部子概念都能过三连追问。
15
+
16
+ 输出:学习笔记 = 子概念清单(✅已内化/⚠️有缺口+缺口描述)+ 我的原话讲解中被纠正的表述对照。
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: 生成复习闪卡——Q&A 卡 + 填空卡,附间隔复习排程
3
+ argument-hint: "<材料来源:文件/主题/近期会话>"
4
+ ---
5
+ 把以下材料做成复习闪卡:$@
6
+
7
+ 规则:
8
+
9
+ 1. **提取**:先通读材料,列出可考察的知识点(定义、机制、对比、数值、流程步骤),按重要性排序,数量 10-20 张。
10
+ 2. **两种卡型**:
11
+ - Q&A 卡:问题正面,答案背面;问题要具体到能唯一作答(禁止「谈谈 XX」式开放题)
12
+ - 填空卡(cloze):挖掉关键词的陈述句,关键词放背面
13
+ 3. **反直觉优先**:材料中违反直觉、容易混淆、我此前答错过的知识点,必须出卡且可出双卡(同一知识点 Q&A + cloze 各一)。
14
+ 4. **输出格式**:Markdown 表格(| 正面 | 背面 | 类型 |),可直接导入 Anki(或存为 .txt 制卡)。
15
+ 5. **排程**:按间隔重复(1 天 / 3 天 / 7 天 / 14 天 / 30 天)给出一轮复习计划表,注明每轮重点卡范围。
16
+
17
+ 铁律:每张卡的答案必须能在原材料中找到出处;材料没有的内容不出卡。
@@ -0,0 +1,14 @@
1
+ ---
2
+ description: 苏格拉底式检验——你提问我作答,暴露理解的真实边界
3
+ argument-hint: "<检验主题>"
4
+ ---
5
+ 对我进行苏格拉底式提问,检验我对「$@」的理解深度。
6
+
7
+ 规则:
8
+
9
+ 1. **你只提问,不讲解**:每次只问一个问题,等我的回答后再决定下一问。
10
+ 2. **提问路径**:从我的断言出发,沿「定义 → 边界 → 反例 → 与相邻概念的区分 → 应用后果」递进;我的每个回答里不严谨的用词都要被追问。
11
+ 3. **标记**:我答对 → 简短确认并深入一层;我答错或含糊 → 不给答案,换个角度再问一次;连续两次答不出 → 停下,指出知识缺口的准确位置,问我是否要转入费曼式补漏。
12
+ 4. **收尾**:十问之后(或我要求停止时)给总结——已稳固的理解 / 摇摆的理解(附典型错误说法)/ 空白区,以及建议的下一步。
13
+
14
+ 禁止:一次列一堆问题让我书面作答;我答错时直接纠正(要引导我自己发现矛盾)。
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: eli5
3
+ description: "ELI5 大白话解释:类比优先、零术语、三档深度递进。Use when the user asks to explain like I'm 5, 用大白话解释, 讲得通俗一点, 我是小白, or is confused by jargon-heavy explanations and needs a ground-up restart."
4
+ version: 1
5
+ license: MIT
6
+ ---
7
+
8
+ # ELI5 — Explain Like I'm 5
9
+
10
+ 把任何概念讲到五岁小孩能懂。核心不是「简化」,是**换锚点**:从对方已有的生活经验出发重建理解,而不是从术语出发往下稀释。
11
+
12
+ ## 何时触发
13
+
14
+ - 用户明确要求 ELI5 / 大白话 / 通俗讲
15
+ - 用户对先前解释回复「没懂」「太抽象」「说人话」
16
+ - 概念解释连续两轮失败后的强制降档
17
+
18
+ ## 解释规则
19
+
20
+ 1. **类比先行**:先用一个生活类比把直觉立起来,再谈概念本身。类比要选用户世界里的东西(做饭、寄快递、班级管理、打电话),不要选另一个技术概念当类比。
21
+ 2. **零术语首过**:第一段解释不允许出现任何领域术语;必须引用术语时,先用大白话定义它再使用。
22
+ 3. **三档递进**:默认输出三档——
23
+ - 🧒 **5 岁版**:一个类比 + 三句话
24
+ - 🧑 **12 岁版**:类比展开 + 工作机制 + 一个具体例子
25
+ - 🧑‍💻 **成人版**:完整机制 + 边界条件 + 与相邻概念的关系
26
+ 用户没指定档位时三档都给,让用户自己选停留深度。
27
+ 4. **一个例子一个反例**:正向例子说清「是什么」,反例划清「不是什么」(例如解释哈希表:正向是「按名字首字母归档的电话簿」,反例是「不是按存放顺序找的抽屉」)。
28
+ 5. **检查理解**:结尾抛一个 One-shot 小问题(用刚讲的类比回答),答对才算过。
29
+
30
+ ## 禁止
31
+
32
+ - 用术语解释术语(「指针是指向内存地址的变量」❌)
33
+ - 类比链超过一层(用 A 比 B,再用 B 比 C,用户会在第二层丢失)
34
+ - 省略反例(没有反例的类比必然过度泛化)
35
+ - 「就是这样,记住就行」——记不住的,能记住的只有锚点
@@ -76,6 +76,7 @@ import path from "node:path";
76
76
  import os from "node:os";
77
77
  import { spawnSync } from "node:child_process";
78
78
  import { fileURLToPath } from "node:url";
79
+ import { createHash } from "node:crypto";
79
80
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
80
81
 
81
82
  // ── 类型 ────────────────────────────────────────────────────
@@ -429,6 +430,8 @@ export interface CorePaths {
429
430
  projectSettingsFile: string; // <cwd>/.pi/settings.json
430
431
  projectStateFile: string; // <cwd>/.pi/scenes-state.json
431
432
  projectScenesRoot: string; // <cwd>/.pi/scenes
433
+ // v0.10:vendored 资产指纹(包内预设 vs 用户落盘的安全更新基线)
434
+ assetsManifest: string; // <scenesRoot>/.assets-manifest.json
432
435
  }
433
436
 
434
437
  export function makeCore(baseDir: string, projectDir?: string) {
@@ -446,6 +449,7 @@ export function makeCore(baseDir: string, projectDir?: string) {
446
449
  projectSettingsFile: path.join(projDir, "settings.json"),
447
450
  projectStateFile: path.join(projDir, "scenes-state.json"),
448
451
  projectScenesRoot: path.join(projDir, "scenes"),
452
+ assetsManifest: path.join(baseDir, "scenes", ".assets-manifest.json"),
449
453
  };
450
454
 
451
455
  function loadScenes(): ScenesFile {
@@ -981,10 +985,140 @@ export function makeCore(baseDir: string, projectDir?: string) {
981
985
  return { tools, commands };
982
986
  }
983
987
 
988
+ // ── v0.10:vendored 资产指纹与安全更新 ──────────────────
989
+ // 问题:scaffold 只补缺失不更新(copyTreeIfMissing 语义),包升级改了预置资产后
990
+ // 用户落盘永远是旧版,且无感知。方案:manifest 记录「上次同步时的内容 hash」作
991
+ // 为预设基线——用户未改过(落盘==基线)→ 跟随包新版;用户改过 → 保留用户版。
992
+ // 所有权语义:预设层(vendored)≠ 资产层(包)≠ 激活层(settings),移交但不断更。
993
+
994
+ function hashFileContent(file: string): string {
995
+ return createHash("sha256").update(fs.readFileSync(file)).digest("hex");
996
+ }
997
+
998
+ /** 目录指纹:递归收集 [相对路径, 文件hash] 排序后整体 hash(文件集变更即变) */
999
+ function hashDirContent(dir: string): string {
1000
+ const parts: string[] = [];
1001
+ const walk = (d: string, rel: string) => {
1002
+ for (const e of fs.readdirSync(d, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
1003
+ const full = path.join(d, e.name);
1004
+ if (e.isDirectory()) walk(full, `${rel}${e.name}/`);
1005
+ else parts.push(`${rel}${e.name}:${hashFileContent(full)}`);
1006
+ }
1007
+ };
1008
+ walk(dir, "");
1009
+ return createHash("sha256").update(parts.join("\n")).digest("hex");
1010
+ }
1011
+
1012
+ type AssetsManifest = { files: Record<string, string> };
1013
+
1014
+ function loadAssetsManifest(): AssetsManifest {
1015
+ // readJson 返回的就是 { files: {...} } 整体,不能再包一层
1016
+ return readJson<AssetsManifest>(paths.assetsManifest, { files: {} });
1017
+ }
1018
+
1019
+ function saveAssetsManifest(m: AssetsManifest): void {
1020
+ writeJson(paths.assetsManifest, m);
1021
+ }
1022
+
1023
+ /** 包内 vendored 资产全集:键=相对 scenesRoot 路径,值={pkgPath(绝对), isDir, hash} */
1024
+ function enumeratePkgAssets(assetsRoots: { skills: string; prompts: string }): Map<string, { pkgPath: string; isDir: boolean; hash: string }> {
1025
+ const out = new Map<string, { pkgPath: string; isDir: boolean; hash: string }>();
1026
+ const skillsRoot = assetsRoots.skills;
1027
+ if (fs.existsSync(skillsRoot)) {
1028
+ for (const scene of fs.readdirSync(skillsRoot)) {
1029
+ const sceneDir = path.join(skillsRoot, scene);
1030
+ if (!fs.statSync(sceneDir).isDirectory()) continue;
1031
+ for (const skill of fs.readdirSync(sceneDir)) {
1032
+ const pkgPath = path.join(sceneDir, skill);
1033
+ if (!fs.statSync(pkgPath).isDirectory()) continue;
1034
+ if (!fs.existsSync(path.join(pkgPath, "SKILL.md"))) continue; // 与 scaffold 同过滤
1035
+ out.set(`${scene}/skills/${skill}`, { pkgPath, isDir: true, hash: hashDirContent(pkgPath) });
1036
+ }
1037
+ }
1038
+ }
1039
+ const promptsRoot = assetsRoots.prompts;
1040
+ if (fs.existsSync(promptsRoot)) {
1041
+ for (const scene of fs.readdirSync(promptsRoot)) {
1042
+ const sceneDir = path.join(promptsRoot, scene);
1043
+ if (!fs.statSync(sceneDir).isDirectory()) continue;
1044
+ for (const f of fs.readdirSync(sceneDir)) {
1045
+ if (!f.endsWith(".md")) continue;
1046
+ const pkgPath = path.join(sceneDir, f);
1047
+ out.set(`${scene}/prompts/${f}`, { pkgPath, isDir: false, hash: hashFileContent(pkgPath) });
1048
+ }
1049
+ }
1050
+ }
1051
+ return out;
1052
+ }
1053
+
1054
+ type AssetsSyncReport = {
1055
+ added: string[];
1056
+ updated: string[];
1057
+ conflicts: string[];
1058
+ removed: string[];
1059
+ baselineRepaired: string[];
1060
+ };
1061
+
1062
+ /** 同步包内 vendored 资产到用户落盘(安全更新):
1063
+ * added=补缺失;updated=用户未改且包有新版→覆盖;conflicts=用户改过→保留用户版;
1064
+ * removed=manifest 有记录但包内已删→仅提示不删;baselineRepaired=无基线且与包一致→补录。
1065
+ * assetsRoots 可注入(测试用),缺省从本扩展包根推导。 */
1066
+ function syncVendoredAssets(assetsRoots?: { skills: string; prompts: string }): AssetsSyncReport {
1067
+ const report: AssetsSyncReport = { added: [], updated: [], conflicts: [], removed: [], baselineRepaired: [] };
1068
+ let pkgRoot: string;
1069
+ try {
1070
+ pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
1071
+ } catch {
1072
+ return report;
1073
+ }
1074
+ const roots = assetsRoots ?? { skills: path.join(pkgRoot, "assets", "scene-skills"), prompts: path.join(pkgRoot, "assets", "scene-prompts") };
1075
+ const pkgAssets = enumeratePkgAssets(roots);
1076
+ const manifest = loadAssetsManifest();
1077
+ for (const [key, info] of pkgAssets) {
1078
+ const dst = path.join(paths.scenesRoot, key);
1079
+ if (!fs.existsSync(dst)) {
1080
+ fs.cpSync(info.pkgPath, dst, { recursive: true });
1081
+ manifest.files[key] = info.hash;
1082
+ report.added.push(key);
1083
+ continue;
1084
+ }
1085
+ const userHash = info.isDir ? hashDirContent(dst) : hashFileContent(dst);
1086
+ const baseHash = manifest.files[key];
1087
+ if (baseHash === undefined) {
1088
+ // 无基线(manifest 机制引入前的落盘):与包一致→补录基线;不一致→保守冲突
1089
+ if (userHash === info.hash) {
1090
+ manifest.files[key] = info.hash;
1091
+ report.baselineRepaired.push(key);
1092
+ } else {
1093
+ report.conflicts.push(key);
1094
+ }
1095
+ } else if (userHash === baseHash) {
1096
+ // 用户未改:跟随包新版
1097
+ if (userHash !== info.hash) {
1098
+ fs.rmSync(dst, { recursive: true });
1099
+ fs.cpSync(info.pkgPath, dst, { recursive: true });
1100
+ manifest.files[key] = info.hash;
1101
+ report.updated.push(key);
1102
+ }
1103
+ } else {
1104
+ // 用户改过:保留用户版(不动 manifest 基线)
1105
+ report.conflicts.push(key);
1106
+ }
1107
+ }
1108
+ // 包内已删的预设:仅报告(不自动删用户文件)
1109
+ for (const key of Object.keys(manifest.files)) {
1110
+ if (!pkgAssets.has(key)) report.removed.push(key);
1111
+ }
1112
+ saveAssetsManifest(manifest);
1113
+ return report;
1114
+ }
1115
+
984
1116
  /**
985
1117
  * 生成模板 scenes.json + 场景 skill 目录骨架 + 预置精选技能。
986
1118
  * 预设均为真实存在的包(npm/git,2026-09 核验);git 技能包用 object form
987
- * 按场景裁剪 skills 子集(anthropics/skills 16M 全量 / openclaw/agent-skills 1.9M)。
1119
+ * 按场景裁剪 skills 子集(anthropics/skills 16M 全量)。曾用 openclaw/agent-skills
1120
+ * (v0.8.1 移除:定位为 OpenClaw 项目专用工作流库而非通用编码技能;autoreview/handoff
1121
+ * 的职责已由 pi-simplify / pi-subagents 覆盖)。
988
1122
  * 预置技能 vendored 自高质量开源技能(MIT,见各自 SKILL.md 尾部归属声明)。
989
1123
  */
990
1124
  function scaffold(): string[] {
@@ -1008,10 +1142,6 @@ export function makeCore(baseDir: string, projectDir?: string) {
1008
1142
  "npm:pi-subagents", // 单代理委派 + 脚本化多代理工作流
1009
1143
  "npm:pi-git-worktree", // git worktree 并行开发
1010
1144
  "npm:pi-simplify", // 近期变更代码审查(清晰度/一致性/可维护性)
1011
- {
1012
- source: "git:github.com/openclaw/agent-skills", // OpenClaw 官方编码工作流技能(1.9M)
1013
- skills: ["skills/autoreview", "skills/handoff"], // 独立代码审查 / 跨代理任务交接
1014
- },
1015
1145
  {
1016
1146
  source: "git:github.com/anthropics/skills", // Anthropic 官方技能库(16M),按需子集
1017
1147
  skills: ["skills/frontend-design", "skills/webapp-testing", "skills/mcp-builder"],
@@ -1078,13 +1208,23 @@ export function makeCore(baseDir: string, projectDir?: string) {
1078
1208
  skills: ["~/.pi/agent/scenes/data/skills"],
1079
1209
  prompts: ["~/.pi/agent/scenes/data/prompts"], // scaffold 预置 data-audit 数据审计
1080
1210
  },
1211
+ learning: {
1212
+ description: "学习:知识内化、费曼检验、闪卡复习",
1213
+ icon: "📚",
1214
+ packages: [
1215
+ "npm:pi-web-access", // 查教程/文档/视频理解(学习材料获取)
1216
+ "npm:pi-subagents", // 并行学习:子代理各读一种资料再汇总多视角笔记
1217
+ ],
1218
+ skills: ["~/.pi/agent/scenes/learning/skills"],
1219
+ prompts: ["~/.pi/agent/scenes/learning/prompts"], // scaffold 预置 feynman / socratic / flashcards
1220
+ },
1081
1221
  },
1082
1222
  };
1083
1223
  if (!fs.existsSync(paths.scenesFile)) {
1084
1224
  writeJson(paths.scenesFile, template);
1085
1225
  created.push(paths.scenesFile);
1086
1226
  }
1087
- for (const s of ["common", "coding", "office", "pm", "research", "writing", "data"]) {
1227
+ for (const s of ["common", "coding", "office", "pm", "research", "writing", "data", "learning"]) {
1088
1228
  for (const kind of ["skills", "prompts"] as const) {
1089
1229
  const dir = path.join(paths.scenesRoot, s, kind);
1090
1230
  if (!fs.existsSync(dir)) {
@@ -1093,37 +1233,13 @@ export function makeCore(baseDir: string, projectDir?: string) {
1093
1233
  }
1094
1234
  }
1095
1235
  }
1096
- // 预置精选技能:从包内 assets/scene-skills/<场景>/ 复制到场景 skill 目录。
1097
- // 仅在目标不存在时写入(幂等,不覆盖用户已有同名技能);复制后归用户所有,可改可删。
1236
+ // v0.10:vendored 预置(技能+模板)统一走安全同步:补缺失 + 记指纹基线 +
1237
+ // 未修改的跟随包新版(用户改过的保留)。所有权语义见 syncVendoredAssets 注释。
1098
1238
  try {
1099
- const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
1100
- const assetsRoot = path.join(pkgRoot, "assets", "scene-skills");
1101
- if (fs.existsSync(assetsRoot)) {
1102
- for (const scene of fs.readdirSync(assetsRoot)) {
1103
- const srcScene = path.join(assetsRoot, scene);
1104
- if (!fs.statSync(srcScene).isDirectory()) continue;
1105
- for (const skill of fs.readdirSync(srcScene)) {
1106
- const src = path.join(srcScene, skill);
1107
- const dst = path.join(paths.scenesRoot, scene, "skills", skill);
1108
- if (!fs.existsSync(path.join(src, "SKILL.md")) || fs.existsSync(dst)) continue;
1109
- fs.cpSync(src, dst, { recursive: true });
1110
- created.push(dst);
1111
- }
1112
- }
1113
- }
1114
- // v0.8:预置场景模板 assets/scene-prompts/<场景>/*.md → scenes/<场景>/prompts/(幂等复制,不覆盖用户已有)
1115
- const promptsAssetsRoot = path.join(pkgRoot, "assets", "scene-prompts");
1116
- if (fs.existsSync(promptsAssetsRoot)) {
1117
- for (const scene of fs.readdirSync(promptsAssetsRoot)) {
1118
- const srcScene = path.join(promptsAssetsRoot, scene);
1119
- if (!fs.statSync(srcScene).isDirectory()) continue;
1120
- const dst = path.join(paths.scenesRoot, scene, "prompts");
1121
- const copied = copyTreeIfMissing(srcScene, dst);
1122
- if (copied > 0) created.push(dst);
1123
- }
1124
- }
1239
+ const report = syncVendoredAssets();
1240
+ for (const key of report.added) created.push(path.join(paths.scenesRoot, key));
1125
1241
  } catch {
1126
- // 资产复制失败不阻断 scaffold(如测试环境无 assets)
1242
+ // 资产同步失败不阻断 scaffold(如测试环境无 assets)
1127
1243
  }
1128
1244
  return created;
1129
1245
  }
@@ -1155,6 +1271,7 @@ export function makeCore(baseDir: string, projectDir?: string) {
1155
1271
  endSession,
1156
1272
  buildToolMap,
1157
1273
  scaffold,
1274
+ syncVendoredAssets,
1158
1275
  };
1159
1276
  }
1160
1277
 
@@ -1311,6 +1428,7 @@ export default function (pi: ExtensionAPI) {
1311
1428
  ["migrate", "把 ≤0.6 遗留的全局场景转为当前项目场景"],
1312
1429
  ["init", "生成模板 scenes.json 与 skill 骨架"],
1313
1430
  ["stats", "用量仪表盘(会话/工具调用/反思)"],
1431
+ ["update-assets", "同步包内预置模板/skill(未修改的跟随新版,改过的保留)"],
1314
1432
  ["evolve", "生成并应用进化提案"],
1315
1433
  ["evolve auto", "开关:会话结束自动应用进化"],
1316
1434
  ];
@@ -1391,6 +1509,26 @@ export default function (pi: ExtensionAPI) {
1391
1509
  return;
1392
1510
  }
1393
1511
 
1512
+ if (arg === "update-assets") {
1513
+ const r = core.syncVendoredAssets();
1514
+ const total = r.added.length + r.updated.length + r.conflicts.length + r.removed.length + r.baselineRepaired.length;
1515
+ if (total === 0) {
1516
+ ctx.ui.notify("预置资产已是最新(无新增/更新/冲突)", "info");
1517
+ return;
1518
+ }
1519
+ const lines = [
1520
+ `预置资产同步(包内 assets → ~/.pi/agent/scenes/):`,
1521
+ r.added.length ? ` + 新增 ${r.added.length}:${r.added.join("、")}` : "",
1522
+ r.updated.length ? ` ↻ 更新 ${r.updated.length}(你未修改,已跟随包新版):${r.updated.join("、")}` : "",
1523
+ r.conflicts.length ? ` ⚠️ 冲突 ${r.conflicts.length}(你改过,保留你的版本):${r.conflicts.join("、")}` : "",
1524
+ r.removed.length ? ` ✂️ 包内已移除 ${r.removed.length}(本地保留未删):${r.removed.join("、")}` : "",
1525
+ r.baselineRepaired.length ? ` ∿ 补录基线 ${r.baselineRepaired.length}(首次纳入指纹管理)` : "",
1526
+ ].filter(Boolean);
1527
+ if (r.updated.length > 0) lines.push("已更新模板/skill,/reload 后生效");
1528
+ ctx.ui.notify(lines.join("\n"), "info");
1529
+ return;
1530
+ }
1531
+
1394
1532
  if (arg === "stats") {
1395
1533
  showStats(ctx);
1396
1534
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-scenes",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Scene switcher for pi: bundle extensions, skills, and prompt templates into a common layer + per-scene layers. /scene hot-switches with live reload (project-scoped, zero settings residue); scene-scoped workflow templates arrive via resources_discover with no config writes; scene definitions self-evolve from real usage (tool-call attribution + session-end LLM reflection).",
5
5
  "keywords": [
6
6
  "pi-package"