pi-scenes 0.13.1 → 0.14.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
@@ -61,6 +61,7 @@ Then `/reload` and `/scene` is live.
61
61
  /scene update-assets # sync preset templates/skills from the package (edits kept, rest updated)
62
62
  /scene evolve # generate & apply evolution proposals (confirm-first)
63
63
  /scene evolve auto # toggle auto-apply at session end (opt-in)
64
+ /scene suggest # scene-suggestion hints on/off (non-blocking; fires only when no scene is active)
64
65
  ```
65
66
 
66
67
  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:
@@ -204,6 +205,15 @@ In short: **installed forever, loaded per scene**. One caveat: extensions you in
204
205
  - **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.
205
206
  - **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`).
206
207
 
208
+ ## Scene suggestions (v0.14)
209
+
210
+ You don't always remember to switch scenes before diving in. pi-scenes can notice and hint — **non-blocking toast, once per session, never auto-switches**:
211
+
212
+ - **History line** (session start): if this project last used a scene (recorded on every project-scoped switch, 30-day window), a toast suggests restoring it: `💻 上次此项目用的是「coding」场景 → /scene coding`
213
+ - **Intent line** (first message): pure keyword heuristics (no LLM, zero cost). Each preset scene carries built-in strong (weight 2) / weak (weight 1) keyword lists; a scene can also declare `keywords` (weight 2). A hint fires only when the best scene scores ≥ 2 AND strictly beats the runner-up (ties stay silent); inputs starting with `/` are never matched
214
+
215
+ Guardrails: one hint per session max (both lines share the budget); silent while any scene is active; after 3 consecutive ignored hints the project cools down until you actually switch (which resets the counter). `/scene suggest on|off` is the master switch (default on). Everything is a `ctx.ui.notify` toast — your typing flow is never interrupted.
216
+
207
217
  ## How it works
208
218
 
209
219
  ```
@@ -236,6 +246,8 @@ In short: **installed forever, loaded per scene**. One caveat: extensions you in
236
246
  | `scenes.<name>.prompts` | prompt-template files/directories (`.md`), `~` expanded; injected via `resources_discover`, never written to settings (v0.8) |
237
247
  | `scenes.<name>.extends` | 🧪 inherit a parent scene (union merge + cycle detection) — forward-compatible entry for parent→child hierarchies |
238
248
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | self-evolution tunables (see "Self-evolution") |
249
+ | `scenes.<name>.keywords` | v0.14 intent-hint keywords (weight 2), stacked on the built-in preset tables |
250
+ | `suggest.enabled` | master switch for scene suggestions (default on; `/scene suggest on\|off`) |
239
251
 
240
252
  ## Scene-scoped prompt templates (v0.8)
241
253
 
@@ -268,6 +280,10 @@ Before uninstalling, `/scene off` and prune entries you don't want to keep from
268
280
 
269
281
  ## Changelog
270
282
 
283
+ ### v0.14.0 (2026-11-28)
284
+
285
+ - **Scene suggestions** — when no scene is active, pi-scenes hints (non-blocking toast, once per session, never auto-switches): a **history line** at session start suggests restoring the scene this project last used (30-day window), and an **intent line** matches your first message against per-scene keyword tables (pure heuristics, no LLM; fires only when the best scene scores ≥ 2 and strictly beats the runner-up). Guardrails: silent while a scene is active, 3 consecutive ignores cool the project down (reset on switch), `/scene suggest on|off` master switch. Scenes accept a new `keywords` field (weight 2) to extend/override the built-in tables
286
+
271
287
  ### v0.13.1 (2026-11-28)
272
288
 
273
289
  - **Coding preset refresh** — the `coding` scaffold preset now ships `npm:pi-lens` (LSP/ast-grep live code feedback) + `npm:pi-subagents` + `git:github.com/mattpocock/skills` via glob whitelists (`skills/engineering/**` + `skills/productivity/grilling/**`; 20 engineering skills follow upstream automatically). Removed `npm:pi-git-worktree`, `npm:pi-simplify` (duties covered by Matt's `code-review`), and the anthropics trio (frontend-design/webapp-testing/mcp-builder) — re-add per taste if you do web UI / MCP work
@@ -385,6 +401,7 @@ pi install git:github.com/Feng-H/pi-scenes
385
401
  /scene update-assets # 同步包内预置模板/skill(未修改跟随新版,改过的保留)
386
402
  /scene evolve # 生成并应用进化提案(逐条确认)
387
403
  /scene evolve auto # 开关:会话结束自动应用(opt-in)
404
+ /scene suggest # 场景意图提示开关(无场景激活时非阻塞建议切换)
388
405
  ```
389
406
 
390
407
  首次运行 `/scene` 会询问是否生成模板,生成后编辑场景定义。模板内置 **八个预设场景 + 通用层**(包均在 npm 核验存在,2026-09):
@@ -523,6 +540,15 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
523
540
  - **本地路径与 npm 写法并存(v0.2.1):** 若 settings 已通过本地路径加载某包(如你的开发目录 `/Users/you/dev/pi-carryover`),场景预设里的 `npm:pi-carryover` 会*借用*你的条目而不安装——跳过 `pi install`,绝不向 settings 追加第二种写法。这一点很关键:同一包双写法 = 同一扩展被加载两份 = pi 启动时工具重名冲突退出。若 settings 已陷入该状态(如手动 `pi install` 造成的重复),`/scene` 会拒绝切换并明确告知需要删除哪个条目。
524
541
  - **热修(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`)。
525
542
 
543
+ ## 场景意图提示(v0.14)
544
+
545
+ 不是每次都会记得先切场景再干活。pi-scenes 可以察觉并提示 —— **非阻塞 toast、每会话至多一次、永不自动切换**:
546
+
547
+ - **历史线**(会话启动):本项目上次用过某场景(每次项目级切换都会记录,30 天有效),启动时提示恢复:`💻 上次此项目用的是「coding」场景 → /scene coding`
548
+ - **意图线**(首条消息):纯关键词启发式(无 LLM、零成本)。每个预置场景有内置词表(强词权重 2 / 弱词权重 1),场景还可用 `keywords` 字段自定义(权重 2)。best 得分 ≥ 2 且严格高于次名才出手(平手静默);以 `/` 开头的命令输入永不参与匹配
549
+
550
+ 防打扰:每会话最多提示一次(两线共享预算);任何场景已激活时静默;连续忽略 3 次项目级冷却,直到你真正切换场景才重置。`/scene suggest on|off` 总开关(缺省开)。全程只是 `ctx.ui.notify` 一行提示,不打断输入流。
551
+
526
552
  ## 工作原理
527
553
 
528
554
  ```
@@ -554,6 +580,8 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
554
580
  | `scenes.<name>.prompts` | prompt 模板文件/目录(`.md`),支持 `~` 展开;经 `resources_discover` 动态注入,永不写 settings(v0.8) |
555
581
  | `scenes.<name>.extends` | 🧪 继承父场景(union 合并,带环检测)——「主场景→子场景」层级的前向兼容入口 |
556
582
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | 自进化阈值(见「自进化」节) |
583
+ | `scenes.<name>.keywords` | v0.14 意图提示关键词(权重 2),叠加在预置内置词表之上 |
584
+ | `suggest.enabled` | 场景意图提示总开关(缺省开;`/scene suggest on\|off`) |
557
585
 
558
586
  ## 场景化 prompt 模板(v0.8)
559
587
 
@@ -586,6 +614,10 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
586
614
 
587
615
  ## 版本历史
588
616
 
617
+ ### v0.14.0(2026-11-28)
618
+
619
+ - **场景意图提示**——无激活场景时非阻塞提示(toast、每会话至多一次、永不自动切换):**历史线**在会话启动时建议恢复本项目上次用的场景(30 天有效);**意图线**把首条消息与各场景关键词表匹配(纯启发式、无 LLM;best ≥ 2 且严格高于次名才出手,平手静默)。防打扰:场景已激活即静默、连续忽略 3 次项目冷却(切换重置)、`/scene suggest on|off` 总开关。场景新增 `keywords` 字段(权重 2)可扩展/覆盖内置词表
620
+
589
621
  ### v0.13.1(2026-11-28)
590
622
 
591
623
  - **coding 预设焕新**——scaffold 预置改为 `npm:pi-lens`(LSP/ast-grep 实时代码反馈)+ `npm:pi-subagents` + `git:github.com/mattpocock/skills`(glob 白名单 `skills/engineering/**` + `skills/productivity/grilling/**`;20 个工程技能随上游自动跟进)。移除 `npm:pi-git-worktree`、`npm:pi-simplify`(职责被 Matt 的 `code-review` 覆盖)与 anthropics 三技能(frontend-design/webapp-testing/mcp-builder)——有 Web UI / MCP 需求可按需加回
@@ -98,6 +98,8 @@ export interface SceneDef {
98
98
  prompts?: string[];
99
99
  /** 场景专有 MCP servers 配置;激活时动态注入 settings.json,切走时精确回收 */
100
100
  mcpServers?: Record<string, unknown>;
101
+ /** v0.14 意图提示自定义关键词(用户声明 → 权重 2,叠加在预置词表之上) */
102
+ keywords?: string[];
101
103
  }
102
104
 
103
105
  export interface EvolveConfig {
@@ -114,6 +116,8 @@ export interface ScenesFile {
114
116
  scenes?: Record<string, SceneDef>;
115
117
  /** 自进化配置(v0.2) */
116
118
  evolve?: EvolveConfig;
119
+ /** v0.14 场景意图提示配置(缺省启用) */
120
+ suggest?: { enabled?: boolean };
117
121
  }
118
122
 
119
123
  export interface ResourceUsage {
@@ -150,6 +154,11 @@ export interface SceneState {
150
154
  version?: number;
151
155
  /** ≤0.6 遗留全局场景的迁移提示是否已弹过(仅全局层 state 使用) */
152
156
  migrateNotified?: boolean;
157
+ /** v0.14 项目最近使用场景(历史线提示数据源;off 不清除,30 天过期) */
158
+ lastScene?: string | null;
159
+ lastSceneAt?: string;
160
+ /** v0.14 意图提示记账:连续忽略计数(≥3 冷却静默,切换场景重置) */
161
+ suggest?: { ignoreStreak: number; lastSuggestedAt?: string };
153
162
  }
154
163
 
155
164
  export interface ApplyResult {
@@ -489,6 +498,12 @@ export function makeCore(baseDir: string, projectDir?: string) {
489
498
  anchors: Array.isArray(s.anchors) ? s.anchors : [],
490
499
  version: s.version,
491
500
  migrateNotified: s.migrateNotified,
501
+ lastScene: s.lastScene ?? null,
502
+ lastSceneAt: s.lastSceneAt,
503
+ suggest:
504
+ s.suggest && typeof s.suggest.ignoreStreak === "number"
505
+ ? { ignoreStreak: s.suggest.ignoreStreak, lastSuggestedAt: s.suggest.lastSuggestedAt }
506
+ : undefined,
492
507
  };
493
508
  }
494
509
 
@@ -1484,6 +1499,72 @@ export function makeCore(baseDir: string, projectDir?: string) {
1484
1499
  };
1485
1500
  }
1486
1501
 
1502
+ // ── v0.14 场景意图提示(/scene suggest)──────────────────
1503
+ // 纯关键词启发式(无 LLM):场景可声明 keywords(权重 2,用户声明)+ 预置场景内置词表(强词 2 / 弱词 1)。
1504
+ // 出手条件:best 得分 ≥ 2 且严格高于次名(平手不出手,避免误导);非阻塞 notify,每会话至多一次。
1505
+
1506
+ function suggestEnabled(cfg: ScenesFile): boolean {
1507
+ return cfg.suggest?.enabled !== false;
1508
+ }
1509
+
1510
+ function suggestAllowed(): { ok: boolean; why?: "active" | "muted" } {
1511
+ if (effectiveActive()) return { ok: false, why: "active" };
1512
+ if ((loadProjectState().suggest?.ignoreStreak ?? 0) >= 3) return { ok: false, why: "muted" };
1513
+ return { ok: true };
1514
+ }
1515
+
1516
+ function matchScene(text: string, cfg: ScenesFile): { name: string; score: number } | null {
1517
+ const lower = text.toLowerCase();
1518
+ let best: { name: string; score: number } | null = null;
1519
+ let second = 0;
1520
+ for (const [name, def] of Object.entries(cfg.scenes ?? {})) {
1521
+ const preset = PRESET_KEYWORDS[name];
1522
+ const userKw = Array.isArray(def.keywords) ? def.keywords : [];
1523
+ let score = 0;
1524
+ for (const k of userKw) if (lower.includes(k.toLowerCase())) score += 2;
1525
+ if (preset) {
1526
+ for (const k of preset.strong) if (lower.includes(k.toLowerCase())) score += 2;
1527
+ for (const k of preset.weak) if (lower.includes(k.toLowerCase())) score += 1;
1528
+ }
1529
+ if (score <= 0) continue;
1530
+ if (!best || score > best.score) {
1531
+ second = best ? best.score : second;
1532
+ best = { name, score };
1533
+ } else if (score > second) {
1534
+ second = score;
1535
+ }
1536
+ }
1537
+ if (!best || best.score < 2 || best.score <= second) return null;
1538
+ return best;
1539
+ }
1540
+
1541
+ function recordSuggested(_scene: string): void {
1542
+ const ps = loadProjectState();
1543
+ saveProjectState({
1544
+ ...ps,
1545
+ suggest: { ignoreStreak: ps.suggest?.ignoreStreak ?? 0, lastSuggestedAt: new Date().toISOString() },
1546
+ });
1547
+ }
1548
+
1549
+ /** 会话收尾结算:提示后用户切到了建议场景 → 重置冷却;否则忽略计数 +1(≥3 冷却静默) */
1550
+ function settleSuggested(scene: string | null, activeNow: string | null): void {
1551
+ if (!scene) return;
1552
+ const ps = loadProjectState();
1553
+ const ignoreStreak = activeNow === scene ? 0 : (ps.suggest?.ignoreStreak ?? 0) + 1;
1554
+ saveProjectState({ ...ps, suggest: { ignoreStreak, lastSuggestedAt: ps.suggest?.lastSuggestedAt } });
1555
+ }
1556
+
1557
+ /** 切换场景时记录项目最近使用(历史线数据源)+ 重置提示冷却;off 不清除 lastScene */
1558
+ function recordSceneUse(name: string): void {
1559
+ const ps = loadProjectState();
1560
+ saveProjectState({
1561
+ ...ps,
1562
+ lastScene: name,
1563
+ lastSceneAt: new Date().toISOString(),
1564
+ suggest: { ignoreStreak: 0, lastSuggestedAt: ps.suggest?.lastSuggestedAt },
1565
+ });
1566
+ }
1567
+
1487
1568
  return {
1488
1569
  paths,
1489
1570
  loadScenes,
@@ -1513,6 +1594,12 @@ export function makeCore(baseDir: string, projectDir?: string) {
1513
1594
  scaffold,
1514
1595
  syncVendoredAssets,
1515
1596
  importClaudePlugin,
1597
+ suggestEnabled,
1598
+ suggestAllowed,
1599
+ matchScene,
1600
+ recordSuggested,
1601
+ settleSuggested,
1602
+ recordSceneUse,
1516
1603
  };
1517
1604
  }
1518
1605
 
@@ -1521,9 +1608,47 @@ export function makeCore(baseDir: string, projectDir?: string) {
1521
1608
  const PICKER_OFF = "∅ 仅通用层(关闭场景)";
1522
1609
  const PICKER_CANCEL = "—— 取消";
1523
1610
 
1611
+ /** v0.14 预置场景内置意图词表:strong 权重 2 / weak 权重 1;用户 scenes.json 可用 keywords 覆盖/叠加 */
1612
+ const PRESET_KEYWORDS: Record<string, { strong: string[]; weak: string[] }> = {
1613
+ coding: {
1614
+ strong: ["重构", "refactor", "报错", "调试", "debug", "bug", "单元测试", "单测", "tdd", "类型错误", "编译错误", "报异常", "实现一个", "写个脚本"],
1615
+ weak: ["代码", "函数", "测试", "提交", "commit", "部署", "npm", "git", "脚本", "性能", "代码审查", "依赖"],
1616
+ },
1617
+ office: {
1618
+ strong: ["ppt", "docx", "xlsx", "excel", "幻灯片", "会议纪要", "周报", "写邮件", "邮件草稿", "word文档", "pdf转"],
1619
+ weak: ["文档", "表格", "通知", "公告", "简历", "排版"],
1620
+ },
1621
+ pm: {
1622
+ strong: ["竞品分析", "prd", "需求文档", "用户故事", "roadmap", "排期", "目标拆解", "需求拆解"],
1623
+ weak: ["产品", "需求", "迭代", "里程碑", "优先级", "backlog"],
1624
+ },
1625
+ research: {
1626
+ strong: ["调研", "文献综述", "arxiv", "论文", "深度调研", "行业报告", "信源"],
1627
+ weak: ["检索", "搜集", "多角度", "对比分析", "调查"],
1628
+ },
1629
+ writing: {
1630
+ strong: ["润色", "写文章", "公众号", "推文", "文风", "去ai味", "改写"],
1631
+ weak: ["文章", "写作", "文案", "标题", "摘要", "草稿"],
1632
+ },
1633
+ data: {
1634
+ strong: ["数据分析", "数据清洗", "透视表", "可视化", "sql", "图表", "统计一下"],
1635
+ weak: ["数据", "csv", "数据库", "报表", "统计"],
1636
+ },
1637
+ learning: {
1638
+ strong: ["费曼", "闪卡", "苏格拉底", "eli5", "教我", "通俗易懂"],
1639
+ weak: ["学习", "理解", "概念", "复习", "入门", "讲解"],
1640
+ },
1641
+ productivity: {
1642
+ strong: ["待办", "任务清单", "任务管理"],
1643
+ weak: ["任务", "日程", "计划"],
1644
+ },
1645
+ };
1646
+
1524
1647
  export default function (pi: ExtensionAPI) {
1525
1648
  const baseDir = process.env.PI_SCENES_DIR || path.join(os.homedir(), ".pi", "agent");
1526
1649
  const core = makeCore(baseDir);
1650
+ // v0.14 意图提示会话记账:每会话至多提示一次(历史线 + 意图线共享预算)
1651
+ const suggestSession: { used: boolean; scene: string | null } = { used: false, scene: null };
1527
1652
 
1528
1653
  /**
1529
1654
  * 状态栏常驻场景徽标:项目场景 ◆ <名>(默认层级);全局场景 ◇ <名> ⌘(--global)。
@@ -1632,6 +1757,11 @@ export default function (pi: ExtensionAPI) {
1632
1757
  }
1633
1758
 
1634
1759
  const r = core.applyToSettings(target, name, preInstallPackages, scope);
1760
+ if (scope === "project" && name) {
1761
+ try {
1762
+ core.recordSceneUse(name); // v0.14 项目历史线数据源 + 重置提示冷却
1763
+ } catch { /* 场景历史记录失败不阻断切换 */ }
1764
+ }
1635
1765
  updateSceneBadge(ctx);
1636
1766
  const promptCount = target.prompts.filter((p) => fs.existsSync(p)).length;
1637
1767
  ctx.ui.notify(
@@ -1673,6 +1803,7 @@ export default function (pi: ExtensionAPI) {
1673
1803
  ["update-assets", "同步包内预置模板/skill(未修改的跟随新版,改过的保留)"],
1674
1804
  ["evolve", "生成并应用进化提案"],
1675
1805
  ["evolve auto", "开关:会话结束自动应用进化"],
1806
+ ["suggest", "场景意图提示开关(on/off):无场景时非阻塞建议切换"],
1676
1807
  ];
1677
1808
  for (const [value, description] of subs) items.push({ value, label: value, description });
1678
1809
  const filtered = items.filter((i) => i.value.toLowerCase().startsWith(p));
@@ -1825,6 +1956,21 @@ export default function (pi: ExtensionAPI) {
1825
1956
  return;
1826
1957
  }
1827
1958
 
1959
+ if (arg === "suggest" || arg.startsWith("suggest ")) {
1960
+ const sub = arg.replace(/^suggest\s*/, "").trim();
1961
+ if (sub === "on" || sub === "off") {
1962
+ const cfgNow = core.loadScenes();
1963
+ backupScenes();
1964
+ core.saveScenes({ ...cfgNow, suggest: { ...(cfgNow.suggest ?? {}), enabled: sub === "on" } });
1965
+ }
1966
+ const enabled = core.suggestEnabled(core.loadScenes());
1967
+ ctx.ui.notify(
1968
+ `场景意图提示:${enabled ? "开" : "关"}\n无激活场景时,会话启动(项目历史)或首条消息(关键词命中)→ 非阻塞提示一次;连续忽略 3 次自动冷却,切换场景后重置`,
1969
+ "info",
1970
+ );
1971
+ return;
1972
+ }
1973
+
1828
1974
  if (arg === "off" || arg === "none") {
1829
1975
  // off 无论何种 scope 都摘两层(用户意图 = 全部关掉);资产锚点保留
1830
1976
  await doSwitch(ctx, null, scope);
@@ -2059,6 +2205,25 @@ export default function (pi: ExtensionAPI) {
2059
2205
  } catch { /* 迁移提示失败不阻断 */ }
2060
2206
  }
2061
2207
 
2208
+ // v0.14 历史线:本项目上次用的场景 → 非阻塞提示恢复(reload 不触发;与意图线共享每会话预算)
2209
+ function suggestFromHistory(ctx: any): void {
2210
+ const cfg = core.loadScenes();
2211
+ if (!core.suggestEnabled(cfg)) return;
2212
+ if (!core.suggestAllowed().ok) return;
2213
+ const ps = core.loadProjectState();
2214
+ const name = ps.lastScene;
2215
+ if (!name || !cfg.scenes?.[name]) return;
2216
+ if (ps.lastSceneAt && Date.now() - Date.parse(ps.lastSceneAt) > 30 * 86_400_000) return; // 30 天过期
2217
+ const icon = cfg.scenes[name]?.icon?.trim() || "◆";
2218
+ ctx.ui?.notify(
2219
+ `${icon} 上次此项目用的是「${name}」场景 → /scene ${name} 恢复(提示可用 /scene suggest off 关闭)`,
2220
+ "info",
2221
+ );
2222
+ suggestSession.used = true;
2223
+ suggestSession.scene = name;
2224
+ core.recordSuggested(name);
2225
+ }
2226
+
2062
2227
  // v0.8:场景化 prompt 模板 —— resources_discover 事件动态注入。
2063
2228
  // 每次 startup/reload pi 都会询问本扩展;按当前激活场景返回 promptPaths,
2064
2229
  // 切走后不再返回 → 模板自动消失,零 settings 写入、零残留。
@@ -2072,13 +2237,47 @@ export default function (pi: ExtensionAPI) {
2072
2237
  }
2073
2238
  });
2074
2239
 
2075
- pi.on("session_start", async (_event, ctx) => {
2240
+ pi.on("session_start", async (event, ctx) => {
2241
+ const reason = (event as any)?.reason ?? "startup";
2242
+ suggestSession.used = false;
2243
+ suggestSession.scene = null;
2076
2244
  try {
2077
2245
  const all = readAllSettingsPackages();
2078
2246
  core.beginSession(ctx.sessionManager?.getSessionFile?.() ?? null, [...all.project, ...all.user]);
2079
2247
  } catch { /* 会话记账失败不阻断切换 */ }
2080
2248
  updateSceneBadge(ctx);
2081
2249
  notifyLegacyMigration(ctx);
2250
+ if (reason !== "reload") {
2251
+ try {
2252
+ suggestFromHistory(ctx);
2253
+ } catch { /* 历史场景提示失败不阻断 */ }
2254
+ }
2255
+ });
2256
+
2257
+ // v0.14 意图线:首条非命令消息命中场景关键词 → 非阻塞提示(notify,不打断输入流)。
2258
+ // 每会话至多一次;已激活场景 / 冷却中 / 功能关闭 / 平手时不出手;始终放行输入。
2259
+ pi.on("input", async (event, ctx) => {
2260
+ try {
2261
+ const e = event as any;
2262
+ if (e?.source === "extension") return { action: "continue" };
2263
+ const text = String(e?.text ?? "");
2264
+ if (!text.trim() || text.trimStart().startsWith("/")) return { action: "continue" };
2265
+ if (suggestSession.used) return { action: "continue" };
2266
+ const cfg = core.loadScenes();
2267
+ if (!core.suggestEnabled(cfg)) return { action: "continue" };
2268
+ if (!core.suggestAllowed().ok) return { action: "continue" };
2269
+ const hit = core.matchScene(text, cfg);
2270
+ if (!hit) return { action: "continue" };
2271
+ const icon = cfg.scenes?.[hit.name]?.icon?.trim() || "◆";
2272
+ ctx.ui?.notify(
2273
+ `💡 这条像「${icon} ${hit.name}」的活儿 → /scene ${hit.name} 启用场景(提示可用 /scene suggest off 关闭)`,
2274
+ "info",
2275
+ );
2276
+ suggestSession.used = true;
2277
+ suggestSession.scene = hit.name;
2278
+ core.recordSuggested(hit.name);
2279
+ } catch { /* 意图提示失败不阻断输入 */ }
2280
+ return { action: "continue" };
2082
2281
  });
2083
2282
 
2084
2283
  pi.on("tool_call", async (event) => {
@@ -2090,6 +2289,9 @@ export default function (pi: ExtensionAPI) {
2090
2289
  pi.on("session_shutdown", async (event, ctx) => {
2091
2290
  const reason = (event as any)?.reason ?? "quit";
2092
2291
  if (reason === "reload") return;
2292
+ try {
2293
+ core.settleSuggested(suggestSession.scene, core.effectiveActive());
2294
+ } catch { /* 提示记账失败不阻断 */ }
2093
2295
  try {
2094
2296
  await runReflection(ctx);
2095
2297
  } catch { /* 会话反思失败不阻断 */ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-scenes",
3
- "version": "0.13.1",
3
+ "version": "0.14.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"