pi-scenes 0.9.0 → 0.11.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 +22 -0
- package/extensions/scenes.ts +193 -43
- package/package.json +36 -36
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ active resources = common layer ∪ current scene
|
|
|
21
21
|
- **Scene layers** — per-scenario bundles (coding / office / writing…), loaded only while active
|
|
22
22
|
- **Project-scoped by default (v0.7)** — `/scene office` writes activation entries to `<cwd>/.pi/settings.json`, so a scene belongs to *this* directory only; opening a fresh directory starts clean. `--global` keeps the ≤0.6 all-projects behavior
|
|
23
23
|
- **Asset/activation split (v0.7)** — packages are installed once globally and shared across projects; git skill bundles are pinned as zero-exposure *anchors* (`{source, autoload:false, skills:[]}`) in user settings, while the project layer writes a *delta* (`{source, autoload:false, skills:[...]}`) that enables just the scene's whitelist — one clone, per-project curation, via pi's native delta mechanism
|
|
24
|
+
- **Full spatial isolation for scene packages (v0.11)** — *every* scene package (plain `npm:` specs included, not just filtered git bundles) now lands in the project layer as a universal delta (`{source, autoload:false, skills:["**"], extensions:["**"], ...}`) with a zero-exposure global anchor — one shared install, zero disk duplication, and a fresh directory loads **only the common layer**. Fixes the v0.7-v0.10 behavior where plain npm scene packages leaked into global settings and loaded in every project while the scene was active. Re-activating an existing scene migrates the leaked entries automatically (borrow semantics for user-configured globals is preserved)
|
|
24
25
|
- **Scene-scoped prompt templates (v0.8)** — each scene can also bundle workflow templates (`prompts` field): fixed checklists that pin down step-by-step procedures so the model can't take shortcuts. Scene = **tools + skills + workflow templates** as one unit
|
|
25
26
|
- Switching rewrites `packages`/`skills` in `settings.json`, then `ctx.reload()` hot-reloads — **no pi restart, session untouched**; prompt templates take a different path: injected via pi's `resources_discover` event with **zero settings writes**
|
|
26
27
|
- 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`
|
|
@@ -55,6 +56,7 @@ Then `/reload` and `/scene` is live.
|
|
|
55
56
|
/scene migrate # convert a ≤0.6 legacy global scene into this project's scene
|
|
56
57
|
/scene init # scaffold scenes.json template + scene skill dirs
|
|
57
58
|
/scene stats # usage dashboard: sessions, tool calls, reflections
|
|
59
|
+
/scene update-assets # sync preset templates/skills from the package (edits kept, rest updated)
|
|
58
60
|
/scene evolve # generate & apply evolution proposals (confirm-first)
|
|
59
61
|
/scene evolve auto # toggle auto-apply at session end (opt-in)
|
|
60
62
|
```
|
|
@@ -264,6 +266,15 @@ Before uninstalling, `/scene off` and prune entries you don't want to keep from
|
|
|
264
266
|
|
|
265
267
|
## Changelog
|
|
266
268
|
|
|
269
|
+
### v0.11.0 (2026-09-24)
|
|
270
|
+
|
|
271
|
+
- **Full spatial isolation for scene packages** — plain `npm:` scene packages now land in the *project* layer as a universal delta (`{source, autoload:false, skills:["**"], extensions:["**"], prompts:["**"], themes:["**"]}`) with a zero-exposure global anchor, exactly like filtered git bundles since v0.7. One shared install (no per-project node_modules), and a fresh directory now loads **only the common layer**. Fixes the v0.7–v0.10 leak where scene npm packages sat in global settings and loaded in *every* project while the scene was active somewhere. Re-activating an existing scene migrates leaked entries automatically; user-configured global packages keep borrowed semantics
|
|
272
|
+
|
|
273
|
+
### v0.10.0 (2026-09-23)
|
|
274
|
+
|
|
275
|
+
- **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
|
|
276
|
+
- Scaffold now runs the same safe sync internally (fills missing + records baselines)
|
|
277
|
+
|
|
267
278
|
### v0.9.0 (2026-09-23)
|
|
268
279
|
|
|
269
280
|
- **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)
|
|
@@ -313,6 +324,7 @@ pi 的 `packages` / `skills` 是全局平铺的:所有已安装扩展、所有
|
|
|
313
324
|
- **场景层**:每个场景自己的一组 extension + skill,激活才加载
|
|
314
325
|
- **默认项目级(v0.7)**——`/scene office` 把激活条目写进 `<cwd>/.pi/settings.json`,场景只属于当前目录;新建目录零残留、干净启动。`--global` 保留 ≤0.6 的全目录生效语义
|
|
315
326
|
- **资产/激活分离(v0.7)**——包只全局装一份、所有项目共享;git 技能包在全局层钉为零暴露**锚点**(`{source, autoload:false, skills:[]}`),项目层写 **delta**(`{source, autoload:false, skills:[白名单]}`)按场景启用——借 pi 原生 delta 机制做到「一份克隆、每项目各自的精选」
|
|
327
|
+
- **场景包全面空间隔离(v0.11)**——所有场景包(含裸 `npm:` 串,不再限于带白名单的 git 包)统一落项目层通用 delta(`{source, autoload:false, skills:["**"], extensions:["**"], ...}`)+ 全局零暴露锚点——共享一份安装、零磁盘复制,新目录只加载通用层。修复 v0.7~v0.10 裸 npm 场景包泄漏到全局 settings、场景激活期间所有项目都加载的问题;存量泄漏在重新激活场景时自动迁移修复(用户手配的全局同包仍保持借用语义)
|
|
316
328
|
- **场景化 prompt 模板(v0.8)**——每个场景可携带流程模板(`prompts` 字段):把固定流程的步骤清单固化成 `/命令`,模型无法挑最快路径跳步。场景成为**工具 + 技能 + 流程模板**三位一体
|
|
317
329
|
- 切换 = 改写 `settings.json` 的 `packages`/`skills` → `ctx.reload()` 热重载,**无需重启 pi**;prompt 模板走另一条路:经 pi 的 `resources_discover` 事件动态注入,**零 settings 写入**
|
|
318
330
|
- 每次切换成功后状态栏常驻**场景徽标**(`◆ coding`,或每场景自定义 `icon` 如 `💻 coding`),状态栏随时回答「我现在在哪个场景」——会话启动自动恢复,`/scene off` 清除
|
|
@@ -347,6 +359,7 @@ pi install git:github.com/Feng-H/pi-scenes
|
|
|
347
359
|
/scene migrate # 把 ≤0.6 遗留的全局场景转为当前项目场景
|
|
348
360
|
/scene init # 生成模板 scenes.json + 场景 skill 目录骨架
|
|
349
361
|
/scene stats # 用量仪表盘:会话数 / 工具调用 / 反思评分
|
|
362
|
+
/scene update-assets # 同步包内预置模板/skill(未修改跟随新版,改过的保留)
|
|
350
363
|
/scene evolve # 生成并应用进化提案(逐条确认)
|
|
351
364
|
/scene evolve auto # 开关:会话结束自动应用(opt-in)
|
|
352
365
|
```
|
|
@@ -549,6 +562,15 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
|
|
|
549
562
|
|
|
550
563
|
## 版本历史
|
|
551
564
|
|
|
565
|
+
### v0.11.0(2026-09-24)
|
|
566
|
+
|
|
567
|
+
- **场景包全面空间隔离**——裸 `npm:` 场景包与 v0.7 起的 git 白名单包同等待遇:统一落项目层通用 delta(`{source, autoload:false, skills:["**"], extensions:["**"], prompts:["**"], themes:["**"]}`)+ 全局零暴露锚点。共享一份全局安装(零磁盘复制),新目录只加载**通用层**。修复 v0.7~v0.10 期间裸 npm 场景包写入全局 settings、场景激活期间所有项目都加载的泄漏;重新激活场景即自动迁移修复,用户手配的全局同包保持借用语义
|
|
568
|
+
|
|
569
|
+
### v0.10.0(2026-09-23)
|
|
570
|
+
|
|
571
|
+
- **vendored 资产指纹 + 安全更新**——预置模板/skill 复制到 `~/.pi/agent/scenes/` 时记录内容指纹基线(`.assets-manifest.json`)。新增 `/scene update-assets` 命令同步包内资产到落盘:**你未修改的跟随包新版,你改过的保留你的版本**(列为冲突清单),包内已删除的预设仅提示不自动删。补上「npm 更新不更新 vendored 资产」的缺口——所有权移交不再等于更新断绝
|
|
572
|
+
- scaffold 内部改走同一套安全同步(补缺失 + 记基线)
|
|
573
|
+
|
|
552
574
|
### v0.9.0(2026-09-23)
|
|
553
575
|
|
|
554
576
|
- **新增预设场景 `learning` 📚**(第八个)——知识内化、检验、间隔复习。携带 `pi-web-access`(学习材料)+ `pi-subagents`(并行多视角学习)、三个流程模板(`/feynman` 费曼四步内化、`/socratic` 只问不讲的苏格拉底检验、`/flashcards` Q&A+填空双卡型配间隔复习排程)、vendored 技能 `eli5`(类比先行、零术语首过、5 岁/12 岁/成人三档递进)
|
package/extensions/scenes.ts
CHANGED
|
@@ -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 {
|
|
@@ -542,16 +546,20 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
542
546
|
function computeTarget(
|
|
543
547
|
active: string | null,
|
|
544
548
|
cfg: ScenesFile,
|
|
545
|
-
): { packages: PackageEntry[]; skills: string[]; commonSkills: string[]; sceneSkills: string[]; prompts: string[] } {
|
|
549
|
+
): { packages: PackageEntry[]; commonPackages: PackageEntry[]; scenePackages: PackageEntry[]; skills: string[]; commonSkills: string[]; sceneSkills: string[]; prompts: string[] } {
|
|
546
550
|
const common = cfg.common ?? {};
|
|
547
551
|
let scene: SceneDef = {};
|
|
548
552
|
if (active) scene = resolveScene(active, cfg);
|
|
549
|
-
|
|
553
|
+
// v0.9 空间隔离:拆分归属——与通用层同身份的场景包归通用层(常驻语义优先,防双层重复)
|
|
554
|
+
const commonPackages = dedupeEntries([...(common.packages ?? [])]);
|
|
555
|
+
const scenePackagesAll = dedupeEntries([...(scene.packages ?? [])]);
|
|
556
|
+
const scenePackages = scenePackagesAll.filter((e) => !commonPackages.some((c) => sameResource(c, e)));
|
|
557
|
+
const packages = dedupeByIdentity(dedupeEntries([...commonPackages, ...scenePackagesAll]));
|
|
550
558
|
const commonSkills = [...new Set([...(common.skills ?? [])].map(expandHome))];
|
|
551
559
|
const sceneSkills = [...new Set([...(scene.skills ?? [])].map(expandHome))];
|
|
552
560
|
const skills = [...new Set([...commonSkills, ...sceneSkills])];
|
|
553
561
|
const prompts = [...new Set([...(common.prompts ?? []), ...(scene.prompts ?? [])].map(expandHome))];
|
|
554
|
-
return { packages, skills, commonSkills, sceneSkills, prompts };
|
|
562
|
+
return { packages, commonPackages, scenePackages, skills, commonSkills, sceneSkills, prompts };
|
|
555
563
|
}
|
|
556
564
|
|
|
557
565
|
/** 包是否已安装(探测 npm 目录 / git clone 目录 / 本地路径) */
|
|
@@ -676,8 +684,33 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
676
684
|
const newProjManagedPkgs: PackageEntry[] = [];
|
|
677
685
|
for (const raw of target.packages) {
|
|
678
686
|
// 项目模式下 filtered 条目 → delta 形态(autoload:false 复用全局克隆 + 白名单启用)
|
|
679
|
-
|
|
680
|
-
|
|
687
|
+
// v0.9 空间隔离:项目模式下场景包(含裸 npm 串)一律落项目层 delta,全局层只留零暴露锚点。
|
|
688
|
+
// 裸 spec → 通用 delta(** 通配全启用):复用 delta+锚点机制共享全局安装(零磁盘复制、零重复加载),
|
|
689
|
+
// 加载仅在本项目生效 —— 新目录只见通用层,场景包不再串场。
|
|
690
|
+
const isCommon = (target.commonPackages ?? []).some((c) => sameResource(c, raw));
|
|
691
|
+
const landed = useProject && !isCommon;
|
|
692
|
+
const e: PackageEntry = landed
|
|
693
|
+
? isFilteredEntry(raw)
|
|
694
|
+
? { ...(raw as Record<string, unknown>), autoload: false }
|
|
695
|
+
: { source: specOf(raw), autoload: false, skills: ["**"], extensions: ["**"], prompts: ["**"], themes: ["**"] }
|
|
696
|
+
: raw;
|
|
697
|
+
if (landed) {
|
|
698
|
+
// 用户先前手配的同包全局条目(摘旧后仍在 = 非本次 pi install 写入、非旧版 managed 遗留)
|
|
699
|
+
// → 借用语义:全局已覆盖所有项目,不落项目 delta、不加锚点
|
|
700
|
+
const preUserList = preInstallPackages ?? oldUserPkgs;
|
|
701
|
+
const inCurrentUser = userPkgs.some((x) => sameResource(x, raw));
|
|
702
|
+
const userOwn = inCurrentUser && preUserList.some((x) => sameResource(x, raw));
|
|
703
|
+
if (userOwn) {
|
|
704
|
+
result.borrowedPackages.push(raw);
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (inCurrentUser) userPkgs = userPkgs.filter((x) => !sameResource(x, raw)); // 摘 pi install 刚写入的裸串
|
|
708
|
+
const anchor: PackageEntry = { source: specOf(raw), autoload: false, skills: [] };
|
|
709
|
+
if (!anchors.some((a) => sameResource(a, anchor))) {
|
|
710
|
+
userPkgs.push(anchor);
|
|
711
|
+
anchors.push(anchor);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
681
714
|
let pkgsRef = landed ? projPkgs : userPkgs;
|
|
682
715
|
const sink = landed ? newProjManagedPkgs : newUserManagedPkgs;
|
|
683
716
|
const preList = preInstallPackages ?? (landed ? oldProjPkgs : oldUserPkgs);
|
|
@@ -714,15 +747,6 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
714
747
|
sink.push(e);
|
|
715
748
|
result.addedPackages.push(e);
|
|
716
749
|
}
|
|
717
|
-
// 项目层 delta 落地 → 全局层确保资产锚点(零暴露 + 共享全局克隆的 delta base)
|
|
718
|
-
if (landed) {
|
|
719
|
-
const anchor: PackageEntry = { source: specOf(raw), autoload: false, skills: [] };
|
|
720
|
-
const anchored = userPkgs.some((x) => sameResource(x, raw)) || anchors.some((a) => sameResource(a, anchor));
|
|
721
|
-
if (!anchored) {
|
|
722
|
-
userPkgs.push(anchor);
|
|
723
|
-
anchors.push(anchor);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
750
|
}
|
|
727
751
|
|
|
728
752
|
// skills 按层落点:场景 scaffold 目录(项目模式)映射为项目相对路径 + 幂等复制 vendor
|
|
@@ -981,6 +1005,134 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
981
1005
|
return { tools, commands };
|
|
982
1006
|
}
|
|
983
1007
|
|
|
1008
|
+
// ── v0.10:vendored 资产指纹与安全更新 ──────────────────
|
|
1009
|
+
// 问题:scaffold 只补缺失不更新(copyTreeIfMissing 语义),包升级改了预置资产后
|
|
1010
|
+
// 用户落盘永远是旧版,且无感知。方案:manifest 记录「上次同步时的内容 hash」作
|
|
1011
|
+
// 为预设基线——用户未改过(落盘==基线)→ 跟随包新版;用户改过 → 保留用户版。
|
|
1012
|
+
// 所有权语义:预设层(vendored)≠ 资产层(包)≠ 激活层(settings),移交但不断更。
|
|
1013
|
+
|
|
1014
|
+
function hashFileContent(file: string): string {
|
|
1015
|
+
return createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** 目录指纹:递归收集 [相对路径, 文件hash] 排序后整体 hash(文件集变更即变) */
|
|
1019
|
+
function hashDirContent(dir: string): string {
|
|
1020
|
+
const parts: string[] = [];
|
|
1021
|
+
const walk = (d: string, rel: string) => {
|
|
1022
|
+
for (const e of fs.readdirSync(d, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1023
|
+
const full = path.join(d, e.name);
|
|
1024
|
+
if (e.isDirectory()) walk(full, `${rel}${e.name}/`);
|
|
1025
|
+
else parts.push(`${rel}${e.name}:${hashFileContent(full)}`);
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
walk(dir, "");
|
|
1029
|
+
return createHash("sha256").update(parts.join("\n")).digest("hex");
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
type AssetsManifest = { files: Record<string, string> };
|
|
1033
|
+
|
|
1034
|
+
function loadAssetsManifest(): AssetsManifest {
|
|
1035
|
+
// readJson 返回的就是 { files: {...} } 整体,不能再包一层
|
|
1036
|
+
return readJson<AssetsManifest>(paths.assetsManifest, { files: {} });
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
function saveAssetsManifest(m: AssetsManifest): void {
|
|
1040
|
+
writeJson(paths.assetsManifest, m);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/** 包内 vendored 资产全集:键=相对 scenesRoot 路径,值={pkgPath(绝对), isDir, hash} */
|
|
1044
|
+
function enumeratePkgAssets(assetsRoots: { skills: string; prompts: string }): Map<string, { pkgPath: string; isDir: boolean; hash: string }> {
|
|
1045
|
+
const out = new Map<string, { pkgPath: string; isDir: boolean; hash: string }>();
|
|
1046
|
+
const skillsRoot = assetsRoots.skills;
|
|
1047
|
+
if (fs.existsSync(skillsRoot)) {
|
|
1048
|
+
for (const scene of fs.readdirSync(skillsRoot)) {
|
|
1049
|
+
const sceneDir = path.join(skillsRoot, scene);
|
|
1050
|
+
if (!fs.statSync(sceneDir).isDirectory()) continue;
|
|
1051
|
+
for (const skill of fs.readdirSync(sceneDir)) {
|
|
1052
|
+
const pkgPath = path.join(sceneDir, skill);
|
|
1053
|
+
if (!fs.statSync(pkgPath).isDirectory()) continue;
|
|
1054
|
+
if (!fs.existsSync(path.join(pkgPath, "SKILL.md"))) continue; // 与 scaffold 同过滤
|
|
1055
|
+
out.set(`${scene}/skills/${skill}`, { pkgPath, isDir: true, hash: hashDirContent(pkgPath) });
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
const promptsRoot = assetsRoots.prompts;
|
|
1060
|
+
if (fs.existsSync(promptsRoot)) {
|
|
1061
|
+
for (const scene of fs.readdirSync(promptsRoot)) {
|
|
1062
|
+
const sceneDir = path.join(promptsRoot, scene);
|
|
1063
|
+
if (!fs.statSync(sceneDir).isDirectory()) continue;
|
|
1064
|
+
for (const f of fs.readdirSync(sceneDir)) {
|
|
1065
|
+
if (!f.endsWith(".md")) continue;
|
|
1066
|
+
const pkgPath = path.join(sceneDir, f);
|
|
1067
|
+
out.set(`${scene}/prompts/${f}`, { pkgPath, isDir: false, hash: hashFileContent(pkgPath) });
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
return out;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
type AssetsSyncReport = {
|
|
1075
|
+
added: string[];
|
|
1076
|
+
updated: string[];
|
|
1077
|
+
conflicts: string[];
|
|
1078
|
+
removed: string[];
|
|
1079
|
+
baselineRepaired: string[];
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
/** 同步包内 vendored 资产到用户落盘(安全更新):
|
|
1083
|
+
* added=补缺失;updated=用户未改且包有新版→覆盖;conflicts=用户改过→保留用户版;
|
|
1084
|
+
* removed=manifest 有记录但包内已删→仅提示不删;baselineRepaired=无基线且与包一致→补录。
|
|
1085
|
+
* assetsRoots 可注入(测试用),缺省从本扩展包根推导。 */
|
|
1086
|
+
function syncVendoredAssets(assetsRoots?: { skills: string; prompts: string }): AssetsSyncReport {
|
|
1087
|
+
const report: AssetsSyncReport = { added: [], updated: [], conflicts: [], removed: [], baselineRepaired: [] };
|
|
1088
|
+
let pkgRoot: string;
|
|
1089
|
+
try {
|
|
1090
|
+
pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
1091
|
+
} catch {
|
|
1092
|
+
return report;
|
|
1093
|
+
}
|
|
1094
|
+
const roots = assetsRoots ?? { skills: path.join(pkgRoot, "assets", "scene-skills"), prompts: path.join(pkgRoot, "assets", "scene-prompts") };
|
|
1095
|
+
const pkgAssets = enumeratePkgAssets(roots);
|
|
1096
|
+
const manifest = loadAssetsManifest();
|
|
1097
|
+
for (const [key, info] of pkgAssets) {
|
|
1098
|
+
const dst = path.join(paths.scenesRoot, key);
|
|
1099
|
+
if (!fs.existsSync(dst)) {
|
|
1100
|
+
fs.cpSync(info.pkgPath, dst, { recursive: true });
|
|
1101
|
+
manifest.files[key] = info.hash;
|
|
1102
|
+
report.added.push(key);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
const userHash = info.isDir ? hashDirContent(dst) : hashFileContent(dst);
|
|
1106
|
+
const baseHash = manifest.files[key];
|
|
1107
|
+
if (baseHash === undefined) {
|
|
1108
|
+
// 无基线(manifest 机制引入前的落盘):与包一致→补录基线;不一致→保守冲突
|
|
1109
|
+
if (userHash === info.hash) {
|
|
1110
|
+
manifest.files[key] = info.hash;
|
|
1111
|
+
report.baselineRepaired.push(key);
|
|
1112
|
+
} else {
|
|
1113
|
+
report.conflicts.push(key);
|
|
1114
|
+
}
|
|
1115
|
+
} else if (userHash === baseHash) {
|
|
1116
|
+
// 用户未改:跟随包新版
|
|
1117
|
+
if (userHash !== info.hash) {
|
|
1118
|
+
fs.rmSync(dst, { recursive: true });
|
|
1119
|
+
fs.cpSync(info.pkgPath, dst, { recursive: true });
|
|
1120
|
+
manifest.files[key] = info.hash;
|
|
1121
|
+
report.updated.push(key);
|
|
1122
|
+
}
|
|
1123
|
+
} else {
|
|
1124
|
+
// 用户改过:保留用户版(不动 manifest 基线)
|
|
1125
|
+
report.conflicts.push(key);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
// 包内已删的预设:仅报告(不自动删用户文件)
|
|
1129
|
+
for (const key of Object.keys(manifest.files)) {
|
|
1130
|
+
if (!pkgAssets.has(key)) report.removed.push(key);
|
|
1131
|
+
}
|
|
1132
|
+
saveAssetsManifest(manifest);
|
|
1133
|
+
return report;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
984
1136
|
/**
|
|
985
1137
|
* 生成模板 scenes.json + 场景 skill 目录骨架 + 预置精选技能。
|
|
986
1138
|
* 预设均为真实存在的包(npm/git,2026-09 核验);git 技能包用 object form
|
|
@@ -1101,37 +1253,13 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
1101
1253
|
}
|
|
1102
1254
|
}
|
|
1103
1255
|
}
|
|
1104
|
-
//
|
|
1105
|
-
//
|
|
1256
|
+
// v0.10:vendored 预置(技能+模板)统一走安全同步:补缺失 + 记指纹基线 +
|
|
1257
|
+
// 未修改的跟随包新版(用户改过的保留)。所有权语义见 syncVendoredAssets 注释。
|
|
1106
1258
|
try {
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
if (fs.existsSync(assetsRoot)) {
|
|
1110
|
-
for (const scene of fs.readdirSync(assetsRoot)) {
|
|
1111
|
-
const srcScene = path.join(assetsRoot, scene);
|
|
1112
|
-
if (!fs.statSync(srcScene).isDirectory()) continue;
|
|
1113
|
-
for (const skill of fs.readdirSync(srcScene)) {
|
|
1114
|
-
const src = path.join(srcScene, skill);
|
|
1115
|
-
const dst = path.join(paths.scenesRoot, scene, "skills", skill);
|
|
1116
|
-
if (!fs.existsSync(path.join(src, "SKILL.md")) || fs.existsSync(dst)) continue;
|
|
1117
|
-
fs.cpSync(src, dst, { recursive: true });
|
|
1118
|
-
created.push(dst);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
// v0.8:预置场景模板 assets/scene-prompts/<场景>/*.md → scenes/<场景>/prompts/(幂等复制,不覆盖用户已有)
|
|
1123
|
-
const promptsAssetsRoot = path.join(pkgRoot, "assets", "scene-prompts");
|
|
1124
|
-
if (fs.existsSync(promptsAssetsRoot)) {
|
|
1125
|
-
for (const scene of fs.readdirSync(promptsAssetsRoot)) {
|
|
1126
|
-
const srcScene = path.join(promptsAssetsRoot, scene);
|
|
1127
|
-
if (!fs.statSync(srcScene).isDirectory()) continue;
|
|
1128
|
-
const dst = path.join(paths.scenesRoot, scene, "prompts");
|
|
1129
|
-
const copied = copyTreeIfMissing(srcScene, dst);
|
|
1130
|
-
if (copied > 0) created.push(dst);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1259
|
+
const report = syncVendoredAssets();
|
|
1260
|
+
for (const key of report.added) created.push(path.join(paths.scenesRoot, key));
|
|
1133
1261
|
} catch {
|
|
1134
|
-
//
|
|
1262
|
+
// 资产同步失败不阻断 scaffold(如测试环境无 assets)
|
|
1135
1263
|
}
|
|
1136
1264
|
return created;
|
|
1137
1265
|
}
|
|
@@ -1163,6 +1291,7 @@ export function makeCore(baseDir: string, projectDir?: string) {
|
|
|
1163
1291
|
endSession,
|
|
1164
1292
|
buildToolMap,
|
|
1165
1293
|
scaffold,
|
|
1294
|
+
syncVendoredAssets,
|
|
1166
1295
|
};
|
|
1167
1296
|
}
|
|
1168
1297
|
|
|
@@ -1319,6 +1448,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1319
1448
|
["migrate", "把 ≤0.6 遗留的全局场景转为当前项目场景"],
|
|
1320
1449
|
["init", "生成模板 scenes.json 与 skill 骨架"],
|
|
1321
1450
|
["stats", "用量仪表盘(会话/工具调用/反思)"],
|
|
1451
|
+
["update-assets", "同步包内预置模板/skill(未修改的跟随新版,改过的保留)"],
|
|
1322
1452
|
["evolve", "生成并应用进化提案"],
|
|
1323
1453
|
["evolve auto", "开关:会话结束自动应用进化"],
|
|
1324
1454
|
];
|
|
@@ -1399,6 +1529,26 @@ export default function (pi: ExtensionAPI) {
|
|
|
1399
1529
|
return;
|
|
1400
1530
|
}
|
|
1401
1531
|
|
|
1532
|
+
if (arg === "update-assets") {
|
|
1533
|
+
const r = core.syncVendoredAssets();
|
|
1534
|
+
const total = r.added.length + r.updated.length + r.conflicts.length + r.removed.length + r.baselineRepaired.length;
|
|
1535
|
+
if (total === 0) {
|
|
1536
|
+
ctx.ui.notify("预置资产已是最新(无新增/更新/冲突)", "info");
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
const lines = [
|
|
1540
|
+
`预置资产同步(包内 assets → ~/.pi/agent/scenes/):`,
|
|
1541
|
+
r.added.length ? ` + 新增 ${r.added.length}:${r.added.join("、")}` : "",
|
|
1542
|
+
r.updated.length ? ` ↻ 更新 ${r.updated.length}(你未修改,已跟随包新版):${r.updated.join("、")}` : "",
|
|
1543
|
+
r.conflicts.length ? ` ⚠️ 冲突 ${r.conflicts.length}(你改过,保留你的版本):${r.conflicts.join("、")}` : "",
|
|
1544
|
+
r.removed.length ? ` ✂️ 包内已移除 ${r.removed.length}(本地保留未删):${r.removed.join("、")}` : "",
|
|
1545
|
+
r.baselineRepaired.length ? ` ∿ 补录基线 ${r.baselineRepaired.length}(首次纳入指纹管理)` : "",
|
|
1546
|
+
].filter(Boolean);
|
|
1547
|
+
if (r.updated.length > 0) lines.push("已更新模板/skill,/reload 后生效");
|
|
1548
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1402
1552
|
if (arg === "stats") {
|
|
1403
1553
|
showStats(ctx);
|
|
1404
1554
|
return;
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
2
|
+
"name": "pi-scenes",
|
|
3
|
+
"version": "0.11.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Feng-H",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Feng-H/pi-scenes.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Feng-H/pi-scenes/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/Feng-H/pi-scenes#readme",
|
|
19
|
+
"files": [
|
|
20
|
+
"extensions",
|
|
21
|
+
"assets",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test test/"
|
|
27
|
+
},
|
|
28
|
+
"pi": {
|
|
29
|
+
"extensions": [
|
|
30
|
+
"./extensions"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
35
|
+
"@earendil-works/pi-ai": "*"
|
|
36
|
+
}
|
|
37
|
+
}
|