psyclaw 0.30.17 → 0.30.19

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.
@@ -14,7 +14,7 @@ import { lstat, mkdir, readFile } from "node:fs/promises";
14
14
  import { PROVIDER_PRESETS, providerCredentialSource, saveProviderConfig } from "../../setup.js";
15
15
  import { dirname } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
- import { coreSkillNames, enabledRecommendedSkillPaths, normalizeRecommendedSkillId, readRecommendationState, readRecommendedCatalog, recommendedSkillTarget, saveRecommendationState, validateModelInstalledRecommendedSkill, } from "../../skills/recommended.js";
17
+ import { coreSkillNames, enabledRecommendedSkillPaths, normalizeRecommendedSkillId, readRecommendationState, readRecommendedCatalog, recommendedSkillTarget, saveRecommendationState, setRecommendedSkillEnabled, validateModelInstalledRecommendedSkill, RecommendedSkillUnavailableError, } from "../../skills/recommended.js";
18
18
  import { buildRecommendedSkillInstallTask } from "../../skills/install-guidance.js";
19
19
  import { SkillManagerComponent } from "../../tui/skill-manager.js";
20
20
  import { BiosignalWizardComponent } from "../../tui/biosignal-wizard.js";
@@ -81,6 +81,21 @@ async function notifyError(ctx, error, extra = {}) {
81
81
  await captureAgentError(error, { phase: "extension", cwd: ctx.cwd, ...extra });
82
82
  ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
83
83
  }
84
+ /** Reload Pi skills/prompts after enablement changes; fall back to asking for /reload. */
85
+ async function notifyAfterSkillChange(ctx, summary, level = "info") {
86
+ if (typeof ctx.reload === "function") {
87
+ try {
88
+ await ctx.reload();
89
+ ctx.ui.notify(`${summary}已自动重新加载。`, level);
90
+ return;
91
+ }
92
+ catch (error) {
93
+ ctx.ui.notify(`${summary}自动加载失败(${error instanceof Error ? error.message : String(error)})。请执行 /reload。`, "warning");
94
+ return;
95
+ }
96
+ }
97
+ ctx.ui.notify(`${summary}请执行 /reload 重新加载。`, level);
98
+ }
84
99
  const activeAgentRuns = new Set();
85
100
  const CORE_SKILLS = new Set(["academic-grill", "research-intake", "evidence-capture", "citation-audit", "analysis-plan"]);
86
101
  function findLastMatching(items, predicate) {
@@ -425,17 +440,22 @@ async function skillManagerRows(root, state) {
425
440
  };
426
441
  }
427
442
  catch (validationError) {
428
- // A managed target that exists on disk but fails validation (e.g. a URL
429
- // install whose manifest/hash does not match the pinned catalog) is still
430
- // shown as installed so the user sees it; enabling it only takes effect
431
- // once the install is repaired through /skill.
443
+ // A directory without SKILL.md is not installed: Space/Enter must start
444
+ // the existing install flow. A present tree that fails content checks
445
+ // stays visible so the user can repair it.
446
+ const unavailable = validationError instanceof RecommendedSkillUnavailableError ? validationError : undefined;
447
+ const missing = unavailable?.code === "missing-files" || unavailable?.code === "not-installed";
432
448
  let onDisk = false;
433
- try {
434
- const target = recommendedSkillTarget(root, id, scope);
435
- const stat = await lstat(target);
436
- onDisk = stat.isDirectory();
449
+ if (!missing) {
450
+ try {
451
+ const target = recommendedSkillTarget(root, id, scope);
452
+ const stat = await lstat(target);
453
+ onDisk = stat.isDirectory() && !stat.isSymbolicLink();
454
+ }
455
+ catch { /* target missing */ }
437
456
  }
438
- catch { /* target missing */ }
457
+ const hasSource = typeof item.sourceRef === "string" && /^https:\/\//.test(item.sourceRef);
458
+ const configuredEnabled = state.skills.includes(id);
439
459
  return {
440
460
  id,
441
461
  name: item.name,
@@ -443,16 +463,21 @@ async function skillManagerRows(root, state) {
443
463
  ...(item.sourceRef === undefined ? {} : { sourceRef: item.sourceRef }),
444
464
  ...(typeof item.installHint === "string" ? { installHint: item.installHint } : {}),
445
465
  collection: item.skillLayout === "collection",
446
- installed: onDisk,
447
- enabled: onDisk && state.skills.includes(id),
466
+ installed: !missing && onDisk,
467
+ enabled: !missing && onDisk && configuredEnabled,
448
468
  scope,
449
- blocked: typeof item.sourceRef !== "string" || !/^https:\/\//.test(item.sourceRef),
450
- reason: onDisk
451
- ? `已检测到目录但未通过来源/许可/哈希校验${state.skills.includes(id) ? "(当前配置为启用,但校验失败不会加载)" : ""};可按 r 重新安装修复`
452
- : typeof item.sourceRef === "string" && /^https:\/\//.test(item.sourceRef)
453
- ? "尚未安装;按 Enter 选择安装范围并交给当前模型处理"
454
- : "没有可交给模型检查的来源网址",
469
+ blocked: (missing && configuredEnabled) || !hasSource,
470
+ reason: unavailable?.code === "missing-files"
471
+ ? "目录存在但缺少 SKILL.md,尚未安装完成;按 Enter 选择安装范围并交给当前模型处理。完成前不会记为已启用。"
472
+ : !missing && onDisk
473
+ ? `已检测到目录但未通过来源/许可/哈希校验${configuredEnabled ? "(当前配置为启用,但校验失败不会加载)" : ""};可按 r 重新安装修复`
474
+ : missing && configuredEnabled
475
+ ? `配置中标记为启用但本地文件缺失;按 Space 可禁用此配置,按 Enter${hasSource ? " 可重新安装" : " 但无可用来源"}`
476
+ : hasSource
477
+ ? "尚未安装;按 Enter 选择安装范围并交给当前模型处理"
478
+ : "没有可交给模型检查的来源网址",
455
479
  source: "recommended",
480
+ ...(missing && configuredEnabled ? { configuredEnabled: true } : {}),
456
481
  };
457
482
  }
458
483
  }));
@@ -541,21 +566,6 @@ function skillRowLabel(row) {
541
566
  const state = row.blocked ? "× 阻断" : row.enabled ? "● 已启用" : row.installed ? "○ 未启用" : "↓ 未安装";
542
567
  return `${state} ${row.name} [${row.id}]`;
543
568
  }
544
- async function setRecommendedSkillEnabled(root, requestedId, enabled, requestedScope) {
545
- const id = normalizeRecommendedSkillId(requestedId);
546
- const state = await readRecommendationState(root);
547
- const scope = requestedScope ?? state.skillScopes?.[id] ?? "project";
548
- if (enabled)
549
- await validateModelInstalledRecommendedSkill(root, id, scope);
550
- const current = new Set(state.skills);
551
- if (enabled)
552
- current.add(id);
553
- else
554
- current.delete(id);
555
- state.skills = [...current];
556
- state.skillScopes = { ...(state.skillScopes ?? {}), [id]: scope };
557
- await saveRecommendationState(root, state);
558
- }
559
569
  function skillManagerItems(rows) {
560
570
  return [
561
571
  ...coreSkillNames().map((name) => ({
@@ -578,6 +588,7 @@ function skillManagerItems(rows) {
578
588
  : []),
579
589
  ],
580
590
  ...(row.reason === undefined ? {} : { reason: row.reason }),
591
+ ...(row.configuredEnabled === true ? { configuredEnabled: true } : {}),
581
592
  })),
582
593
  ];
583
594
  }
@@ -1002,7 +1013,9 @@ async function showSkillManager(pi, ctx) {
1002
1013
  const failed = [];
1003
1014
  for (const row of managed) {
1004
1015
  try {
1005
- await setRecommendedSkillEnabled(ctx.cwd, row.id, true);
1016
+ const result = await setRecommendedSkillEnabled(ctx.cwd, row.id, true);
1017
+ if (!result.ok)
1018
+ failed.push(row.name);
1006
1019
  }
1007
1020
  catch {
1008
1021
  failed.push(row.name);
@@ -1012,9 +1025,9 @@ async function showSkillManager(pi, ctx) {
1012
1025
  const ids = locals.map((row) => row.name);
1013
1026
  await setLocalSkillsEnabled(ctx.cwd, ids, true);
1014
1027
  }
1015
- ctx.ui.notify(failed.length > 0
1016
- ? `已启用全部可管理的 Skill(${failed.join("、")} 启用失败:可能未通过来源、许可或依赖预检)。请运行 /reload 重新加载。`
1017
- : `已启用全部可管理的 Skill。请运行 /reload 重新加载。`, failed.length > 0 ? "warning" : "info");
1028
+ await notifyAfterSkillChange(ctx, failed.length > 0
1029
+ ? `已启用其余可管理的 Skill(${failed.join("、")} 未启用:缺少 SKILL.md 或未通过校验,请在列表中单独安装或修复)。`
1030
+ : "已启用全部可管理的 Skill。", failed.length > 0 ? "warning" : "info");
1018
1031
  }
1019
1032
  else {
1020
1033
  for (const row of managed) {
@@ -1027,7 +1040,7 @@ async function showSkillManager(pi, ctx) {
1027
1040
  const ids = locals.map((row) => row.name);
1028
1041
  await setLocalSkillsEnabled(ctx.cwd, ids, false);
1029
1042
  }
1030
- ctx.ui.notify("已停用全部可管理的 Skill。请运行 /reload 重新加载。", "info");
1043
+ await notifyAfterSkillChange(ctx, "已停用全部可管理的 Skill。");
1031
1044
  }
1032
1045
  continue;
1033
1046
  }
@@ -1041,11 +1054,21 @@ async function showSkillManager(pi, ctx) {
1041
1054
  if (action.type === "toggle") {
1042
1055
  if (row.source === "local") {
1043
1056
  await setLocalSkillEnabled(ctx.cwd, row.name, action.enabled);
1044
- ctx.ui.notify(`已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。请运行 /reload 重新加载。`, "info");
1057
+ await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。`);
1045
1058
  }
1046
1059
  else {
1047
- await setRecommendedSkillEnabled(ctx.cwd, row.id, action.enabled);
1048
- ctx.ui.notify(`已${action.enabled ? "启用" : "停用"} ${row.name}。请运行 /reload 重新加载。`, "info");
1060
+ const result = await setRecommendedSkillEnabled(ctx.cwd, row.id, action.enabled);
1061
+ if (!result.ok) {
1062
+ const canInstall = action.enabled && result.needsInstall && !row.blocked && typeof row.sourceRef === "string" && row.sourceRef.length > 0;
1063
+ if (canInstall) {
1064
+ ctx.ui.notify(result.message, "warning");
1065
+ await queueModelSkillInstall(pi, ctx, row);
1066
+ return;
1067
+ }
1068
+ ctx.ui.notify(result.message, "error");
1069
+ continue;
1070
+ }
1071
+ await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"} ${row.name}。`);
1049
1072
  }
1050
1073
  }
1051
1074
  }