pi-scenes 0.13.0 → 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:
@@ -68,7 +69,7 @@ First run of `/scene` offers to generate the template. It ships with **eight pre
68
69
  | Scene | Extensions | Skills | Prompt templates (v0.8) |
69
70
  |---|---|---|---|
70
71
  | `common` | `npm:pi-scenes`, `npm:pi-carryover` | — (your own dir) | — |
71
- | `coding` | `npm:pi-lens`, `npm:pi-subagents`, `npm:pi-git-worktree`, `npm:pi-simplify` | `anthropics/skills` → frontend-design, webapp-testing, mcp-builder | `/pre-commit` |
72
+ | `coding` | `npm:pi-lens`, `npm:pi-subagents` | `mattpocock/skills` → engineering/** (20 skills) + productivity/grilling | `/pre-commit` |
72
73
  | `office` | `npm:pi-docparser` | `anthropics/skills` → docx, pptx, xlsx, pdf, internal-comms | `/doc-from-notes` |
73
74
  | `pm` | `npm:pi-web-access`, `npm:pi-goal-x`, `npm:@juicesharp/rpiv-todo`, `npm:@juicesharp/rpiv-ask-user-question` | — | `/prd-skeleton` |
74
75
  | `research` | `npm:pi-web-access`, `npm:pi-subagents` | 预置:arxiv-research, openalex-paper-search | `/deep-dive` |
@@ -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,14 @@ 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
+
287
+ ### v0.13.1 (2026-11-28)
288
+
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
290
+
271
291
  ### v0.12.0 (2026-09-30)
272
292
 
273
293
  * **学习场景 (learning) 重磅升级**:
@@ -381,6 +401,7 @@ pi install git:github.com/Feng-H/pi-scenes
381
401
  /scene update-assets # 同步包内预置模板/skill(未修改跟随新版,改过的保留)
382
402
  /scene evolve # 生成并应用进化提案(逐条确认)
383
403
  /scene evolve auto # 开关:会话结束自动应用(opt-in)
404
+ /scene suggest # 场景意图提示开关(无场景激活时非阻塞建议切换)
384
405
  ```
385
406
 
386
407
  首次运行 `/scene` 会询问是否生成模板,生成后编辑场景定义。模板内置 **八个预设场景 + 通用层**(包均在 npm 核验存在,2026-09):
@@ -388,7 +409,7 @@ pi install git:github.com/Feng-H/pi-scenes
388
409
  | 层 | 预设 packages | 理由 |
389
410
  |---|---|---|
390
411
  | `common` | `npm:pi-scenes`、`npm:pi-carryover` | 切换器自身 + 跨会话承接,恒需 |
391
- | `coding` | `npm:pi-lens`、`npm:pi-subagents`、`npm:pi-git-worktree` | LSP/lint 实时反馈、子代理委派、worktree 并行开发 |
412
+ | `coding` | `npm:pi-lens`、`npm:pi-subagents`、`mattpocock/skills`(engineering/** + grilling) | LSP/lint 实时反馈、子代理委派、Matt Pocock 工程流(grill→spec→tickets→implement→review→pr) |
392
413
  | `office` | `npm:pi-docparser` | PDF/Office 文档解析 |
393
414
  | `pm` | `npm:pi-web-access`、`npm:pi-goal-x`、`npm:@juicesharp/rpiv-todo` | 竞品/市场调研、目标规划与完成度审计、需求/任务清单 overlay |
394
415
  | `research` | `npm:pi-web-access`、`npm:pi-subagents` | 多源搜索/抓取/PDF/视频,并行多角度深挖 |
@@ -519,6 +540,15 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
519
540
  - **本地路径与 npm 写法并存(v0.2.1):** 若 settings 已通过本地路径加载某包(如你的开发目录 `/Users/you/dev/pi-carryover`),场景预设里的 `npm:pi-carryover` 会*借用*你的条目而不安装——跳过 `pi install`,绝不向 settings 追加第二种写法。这一点很关键:同一包双写法 = 同一扩展被加载两份 = pi 启动时工具重名冲突退出。若 settings 已陷入该状态(如手动 `pi install` 造成的重复),`/scene` 会拒绝切换并明确告知需要删除哪个条目。
520
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`)。
521
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
+
522
552
  ## 工作原理
523
553
 
524
554
  ```
@@ -550,6 +580,8 @@ pi-scenes 绝不改第三方包的全局配置——徽标是它放到状态栏
550
580
  | `scenes.<name>.prompts` | prompt 模板文件/目录(`.md`),支持 `~` 展开;经 `resources_discover` 动态注入,永不写 settings(v0.8) |
551
581
  | `scenes.<name>.extends` | 🧪 继承父场景(union 合并,带环检测)——「主场景→子场景」层级的前向兼容入口 |
552
582
  | `evolve.patience` / `evolve.absorbThreshold` / `evolve.skillUnusedThreshold` | 自进化阈值(见「自进化」节) |
583
+ | `scenes.<name>.keywords` | v0.14 意图提示关键词(权重 2),叠加在预置内置词表之上 |
584
+ | `suggest.enabled` | 场景意图提示总开关(缺省开;`/scene suggest on\|off`) |
553
585
 
554
586
  ## 场景化 prompt 模板(v0.8)
555
587
 
@@ -582,6 +614,14 @@ managed 注入的条目在卸载前建议先 `/scene off` + 手工清理 `packag
582
614
 
583
615
  ## 版本历史
584
616
 
617
+ ### v0.14.0(2026-11-28)
618
+
619
+ - **场景意图提示**——无激活场景时非阻塞提示(toast、每会话至多一次、永不自动切换):**历史线**在会话启动时建议恢复本项目上次用的场景(30 天有效);**意图线**把首条消息与各场景关键词表匹配(纯启发式、无 LLM;best ≥ 2 且严格高于次名才出手,平手静默)。防打扰:场景已激活即静默、连续忽略 3 次项目冷却(切换重置)、`/scene suggest on|off` 总开关。场景新增 `keywords` 字段(权重 2)可扩展/覆盖内置词表
620
+
621
+ ### v0.13.1(2026-11-28)
622
+
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 需求可按需加回
624
+
585
625
  ### v0.11.1(2026-09-24)
586
626
 
587
627
  - **锚点形态借用误判修复**——全局层既有的零暴露锚点条目(`{source, autoload:false, skills:[]}`,≤v0.10 写入但 anchors 账本未记录)不再被误判为用户手配的全局配置:重新激活时归一化补入账本并正常落项目 delta,而非按借用跳过
@@ -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 {
@@ -241,7 +250,7 @@ function skillNameOf(file: string): string {
241
250
  if (m) return m[1].trim();
242
251
  const t = head.match(/^#\s+(.+)$/m);
243
252
  if (t) return t[1].trim();
244
- } catch {}
253
+ } catch { /* 头部读取失败:退回文件名 */ }
245
254
  return path.basename(file).replace(/\.md$/i, "");
246
255
  }
247
256
 
@@ -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
 
@@ -1247,16 +1262,14 @@ export function makeCore(baseDir: string, projectDir?: string) {
1247
1262
  },
1248
1263
  scenes: {
1249
1264
  coding: {
1250
- description: "写代码:实时代码反馈、子代理委派、并行分支、变更审查",
1265
+ description: "写代码:实时代码反馈(pi-lens)、子代理委派 + Matt Pocock 工程流(grill→spec→tickets→implement→review→pr)",
1251
1266
  icon: "💻",
1252
1267
  packages: [
1253
1268
  "npm:pi-lens", // LSP/linter/格式化实时代码反馈
1254
- "npm:pi-subagents", // 单代理委派 + 脚本化多代理工作流
1255
- "npm:pi-git-worktree", // git worktree 并行开发
1256
- "npm:pi-simplify", // 近期变更代码审查(清晰度/一致性/可维护性)
1269
+ "npm:pi-subagents", // 单代理委派 + 脚本化多代理工作流(与 implement-spec 并行派工协同)
1257
1270
  {
1258
- source: "git:github.com/anthropics/skills", // Anthropic 官方技能库(16M),按需子集
1259
- skills: ["skills/frontend-design", "skills/webapp-testing", "skills/mcp-builder"],
1271
+ source: "git:github.com/mattpocock/skills", // Matt Pocock 工程技能集(MIT),glob 白名单随上游自动跟进
1272
+ skills: ["skills/engineering/**", "skills/productivity/grilling/**"],
1260
1273
  },
1261
1274
  ],
1262
1275
  skills: ["~/.pi/agent/scenes/coding/skills"],
@@ -1392,7 +1405,7 @@ export function makeCore(baseDir: string, projectDir?: string) {
1392
1405
  try {
1393
1406
  pluginMeta = JSON.parse(fs.readFileSync(mf, "utf8"));
1394
1407
  break;
1395
- } catch {}
1408
+ } catch { /* 清单解析失败:尝试下一个候选 */ }
1396
1409
  }
1397
1410
  }
1398
1411
 
@@ -1458,7 +1471,7 @@ export function makeCore(baseDir: string, projectDir?: string) {
1458
1471
  mcpServers = mcpCfg.mcpServers;
1459
1472
  importedMcpServers.push(...Object.keys(mcpServers));
1460
1473
  }
1461
- } catch {}
1474
+ } catch { /* .mcp.json 非法:忽略 */ }
1462
1475
  }
1463
1476
 
1464
1477
  // 6) 更新 scenes.json
@@ -1486,6 +1499,72 @@ export function makeCore(baseDir: string, projectDir?: string) {
1486
1499
  };
1487
1500
  }
1488
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
+
1489
1568
  return {
1490
1569
  paths,
1491
1570
  loadScenes,
@@ -1515,6 +1594,12 @@ export function makeCore(baseDir: string, projectDir?: string) {
1515
1594
  scaffold,
1516
1595
  syncVendoredAssets,
1517
1596
  importClaudePlugin,
1597
+ suggestEnabled,
1598
+ suggestAllowed,
1599
+ matchScene,
1600
+ recordSuggested,
1601
+ settleSuggested,
1602
+ recordSceneUse,
1518
1603
  };
1519
1604
  }
1520
1605
 
@@ -1523,9 +1608,47 @@ export function makeCore(baseDir: string, projectDir?: string) {
1523
1608
  const PICKER_OFF = "∅ 仅通用层(关闭场景)";
1524
1609
  const PICKER_CANCEL = "—— 取消";
1525
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
+
1526
1647
  export default function (pi: ExtensionAPI) {
1527
1648
  const baseDir = process.env.PI_SCENES_DIR || path.join(os.homedir(), ".pi", "agent");
1528
1649
  const core = makeCore(baseDir);
1650
+ // v0.14 意图提示会话记账:每会话至多提示一次(历史线 + 意图线共享预算)
1651
+ const suggestSession: { used: boolean; scene: string | null } = { used: false, scene: null };
1529
1652
 
1530
1653
  /**
1531
1654
  * 状态栏常驻场景徽标:项目场景 ◆ <名>(默认层级);全局场景 ◇ <名> ⌘(--global)。
@@ -1546,7 +1669,7 @@ export default function (pi: ExtensionAPI) {
1546
1669
  } else {
1547
1670
  ui.setStatus("pi-scene", undefined);
1548
1671
  }
1549
- } catch {}
1672
+ } catch { /* 徽标清理失败不阻断 */ }
1550
1673
  }
1551
1674
 
1552
1675
  /** 读两层 settings 的 packages(供缺失判定与冲突检测) */
@@ -1634,6 +1757,11 @@ export default function (pi: ExtensionAPI) {
1634
1757
  }
1635
1758
 
1636
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
+ }
1637
1765
  updateSceneBadge(ctx);
1638
1766
  const promptCount = target.prompts.filter((p) => fs.existsSync(p)).length;
1639
1767
  ctx.ui.notify(
@@ -1658,7 +1786,7 @@ export default function (pi: ExtensionAPI) {
1658
1786
  try {
1659
1787
  cfg = core.loadScenes();
1660
1788
  active = core.effectiveActive();
1661
- } catch {}
1789
+ } catch { /* 配置不可读:给出空补全 */ }
1662
1790
  const items: Array<{ value: string; label: string; description?: string }> = [];
1663
1791
  for (const [name, def] of Object.entries(cfg.scenes ?? {})) {
1664
1792
  const icon = def?.icon?.trim() || "◆";
@@ -1675,6 +1803,7 @@ export default function (pi: ExtensionAPI) {
1675
1803
  ["update-assets", "同步包内预置模板/skill(未修改的跟随新版,改过的保留)"],
1676
1804
  ["evolve", "生成并应用进化提案"],
1677
1805
  ["evolve auto", "开关:会话结束自动应用进化"],
1806
+ ["suggest", "场景意图提示开关(on/off):无场景时非阻塞建议切换"],
1678
1807
  ];
1679
1808
  for (const [value, description] of subs) items.push({ value, label: value, description });
1680
1809
  const filtered = items.filter((i) => i.value.toLowerCase().startsWith(p));
@@ -1686,7 +1815,7 @@ export default function (pi: ExtensionAPI) {
1686
1815
  let names: string[] = [];
1687
1816
  try {
1688
1817
  names = Object.keys(core.loadScenes().scenes ?? {});
1689
- } catch {}
1818
+ } catch { /* 配置不可读:降级为占位 */ }
1690
1819
  return `切换场景(空格后 Tab 列出并补全):${names.join("/") || "<name>"}`;
1691
1820
  }
1692
1821
 
@@ -1827,6 +1956,21 @@ export default function (pi: ExtensionAPI) {
1827
1956
  return;
1828
1957
  }
1829
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
+
1830
1974
  if (arg === "off" || arg === "none") {
1831
1975
  // off 无论何种 scope 都摘两层(用户意图 = 全部关掉);资产锚点保留
1832
1976
  await doSwitch(ctx, null, scope);
@@ -1918,7 +2062,7 @@ export default function (pi: ExtensionAPI) {
1918
2062
  function backupScenes(): void {
1919
2063
  try {
1920
2064
  if (fs.existsSync(core.paths.scenesFile)) fs.copyFileSync(core.paths.scenesFile, `${core.paths.scenesFile}.scenes-bak`);
1921
- } catch {}
2065
+ } catch { /* 备份失败不阻断主流程 */ }
1922
2066
  }
1923
2067
 
1924
2068
  function shortLabel(k: string): string {
@@ -1926,7 +2070,7 @@ export default function (pi: ExtensionAPI) {
1926
2070
  const v = JSON.parse(k);
1927
2071
  if (typeof v === "string") return v;
1928
2072
  if (v && typeof v === "object" && v.source) return v.source;
1929
- } catch {}
2073
+ } catch { /* 条目不可读:退回路径展示 */ }
1930
2074
  return k.split(path.sep).slice(-2).join("/");
1931
2075
  }
1932
2076
 
@@ -1981,7 +2125,7 @@ export default function (pi: ExtensionAPI) {
1981
2125
  let entries: any[] = [];
1982
2126
  try {
1983
2127
  entries = ctx.sessionManager?.getEntries?.() ?? [];
1984
- } catch {}
2128
+ } catch { /* 条目不可读:视为空 */ }
1985
2129
  const msgs = entries.filter((e) => e?.type === "message").slice(-40);
1986
2130
  return msgs
1987
2131
  .map((e) => {
@@ -2042,7 +2186,7 @@ export default function (pi: ExtensionAPI) {
2042
2186
  `自动进化已应用 ${proposals.length} 条提案(下次重载生效):\n${proposals.map((p) => (p.kind === "absorb" ? `+ ${specOf(p.entry)} → ${p.scene}` : `- ${p.label} (${p.scene})`)).join("\n")}`,
2043
2187
  "info",
2044
2188
  );
2045
- } catch {}
2189
+ } catch { /* 通知失败不阻断 */ }
2046
2190
  }
2047
2191
  }
2048
2192
 
@@ -2058,7 +2202,26 @@ export default function (pi: ExtensionAPI) {
2058
2202
  "info",
2059
2203
  );
2060
2204
  }
2061
- } catch {}
2205
+ } catch { /* 迁移提示失败不阻断 */ }
2206
+ }
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);
2062
2225
  }
2063
2226
 
2064
2227
  // v0.8:场景化 prompt 模板 —— resources_discover 事件动态注入。
@@ -2074,32 +2237,69 @@ export default function (pi: ExtensionAPI) {
2074
2237
  }
2075
2238
  });
2076
2239
 
2077
- 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;
2078
2244
  try {
2079
2245
  const all = readAllSettingsPackages();
2080
2246
  core.beginSession(ctx.sessionManager?.getSessionFile?.() ?? null, [...all.project, ...all.user]);
2081
- } catch {}
2247
+ } catch { /* 会话记账失败不阻断切换 */ }
2082
2248
  updateSceneBadge(ctx);
2083
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" };
2084
2281
  });
2085
2282
 
2086
2283
  pi.on("tool_call", async (event) => {
2087
2284
  try {
2088
2285
  core.recordToolUse((event as any).toolName, getToolMap().tools);
2089
- } catch {}
2286
+ } catch { /* 用量记账失败不阻断 */ }
2090
2287
  });
2091
2288
 
2092
2289
  pi.on("session_shutdown", async (event, ctx) => {
2093
2290
  const reason = (event as any)?.reason ?? "quit";
2094
2291
  if (reason === "reload") return;
2292
+ try {
2293
+ core.settleSuggested(suggestSession.scene, core.effectiveActive());
2294
+ } catch { /* 提示记账失败不阻断 */ }
2095
2295
  try {
2096
2296
  await runReflection(ctx);
2097
- } catch {}
2297
+ } catch { /* 会话反思失败不阻断 */ }
2098
2298
  try {
2099
2299
  core.endSession(reason);
2100
- } catch {}
2300
+ } catch { /* 会话收尾记账失败不阻断 */ }
2101
2301
  try {
2102
2302
  maybeAutoEvolve(ctx, reason);
2103
- } catch {}
2303
+ } catch { /* 自动进化失败不阻断 */ }
2104
2304
  });
2105
2305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-scenes",
3
- "version": "0.13.0",
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"