psyclaw 0.30.19 → 0.30.20

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.
@@ -25,6 +25,7 @@ import { panelHub } from "../../panel/hub.js";
25
25
  import { appendChoiceRecord } from "../../research/choice.js";
26
26
  import { enabledLocalSkillPaths, enabledLocalPromptPaths, readUserSkillState, scanLocalSkills, setLocalSkillEnabled, setLocalSkillsEnabled, skillNamesInPaths, userSkillId, } from "../../skills/user-skills.js";
27
27
  import { RuntimeMcpRegistry, setUserMcpConfigEnabled, } from "../../integrations/mcp-runtime.js";
28
+ import { classifyIrreversibleHostCommand, extractToolCommandText, irreversibleHostBlockReason, } from "../../safety/irreversible-host-ops.js";
28
29
  import { SecretInputComponent, TextInputComponent, ProviderPickerComponent, } from "../../tui/provider-picker.js";
29
30
  import { resolveProviderBaseUrl } from "../../core/provider-endpoint.js";
30
31
  import { isArsPiActive, isArsPiTurn, psyclawArsPatch, setArsPiSessionActive, } from "../../ars/profile.js";
@@ -81,20 +82,25 @@ async function notifyError(ctx, error, extra = {}) {
81
82
  await captureAgentError(error, { phase: "extension", cwd: ctx.cwd, ...extra });
82
83
  ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
83
84
  }
84
- /** Reload Pi skills/prompts after enablement changes; fall back to asking for /reload. */
85
+ /**
86
+ * Reload Pi skills/prompts after enablement changes.
87
+ * Pi treats `ctx.reload()` as terminal for the current handler: notify first,
88
+ * then reload, and never use the old ctx afterward (`"reloaded"` = stop).
89
+ */
85
90
  async function notifyAfterSkillChange(ctx, summary, level = "info") {
86
91
  if (typeof ctx.reload === "function") {
87
92
  try {
93
+ ctx.ui.notify(`${summary}正在重新加载资源…`, level);
88
94
  await ctx.reload();
89
- ctx.ui.notify(`${summary}已自动重新加载。`, level);
90
- return;
95
+ return "reloaded";
91
96
  }
92
97
  catch (error) {
93
98
  ctx.ui.notify(`${summary}自动加载失败(${error instanceof Error ? error.message : String(error)})。请执行 /reload。`, "warning");
94
- return;
99
+ return "manual-reload";
95
100
  }
96
101
  }
97
102
  ctx.ui.notify(`${summary}请执行 /reload 重新加载。`, level);
103
+ return "manual-reload";
98
104
  }
99
105
  const activeAgentRuns = new Set();
100
106
  const CORE_SKILLS = new Set(["academic-grill", "research-intake", "evidence-capture", "citation-audit", "analysis-plan"]);
@@ -1025,9 +1031,11 @@ async function showSkillManager(pi, ctx) {
1025
1031
  const ids = locals.map((row) => row.name);
1026
1032
  await setLocalSkillsEnabled(ctx.cwd, ids, true);
1027
1033
  }
1028
- await notifyAfterSkillChange(ctx, failed.length > 0
1034
+ const outcome = await notifyAfterSkillChange(ctx, failed.length > 0
1029
1035
  ? `已启用其余可管理的 Skill(${failed.join("、")} 未启用:缺少 SKILL.md 或未通过校验,请在列表中单独安装或修复)。`
1030
1036
  : "已启用全部可管理的 Skill。", failed.length > 0 ? "warning" : "info");
1037
+ if (outcome === "reloaded")
1038
+ return;
1031
1039
  }
1032
1040
  else {
1033
1041
  for (const row of managed) {
@@ -1040,7 +1048,8 @@ async function showSkillManager(pi, ctx) {
1040
1048
  const ids = locals.map((row) => row.name);
1041
1049
  await setLocalSkillsEnabled(ctx.cwd, ids, false);
1042
1050
  }
1043
- await notifyAfterSkillChange(ctx, "已停用全部可管理的 Skill。");
1051
+ if ((await notifyAfterSkillChange(ctx, "已停用全部可管理的 Skill。")) === "reloaded")
1052
+ return;
1044
1053
  }
1045
1054
  continue;
1046
1055
  }
@@ -1054,7 +1063,8 @@ async function showSkillManager(pi, ctx) {
1054
1063
  if (action.type === "toggle") {
1055
1064
  if (row.source === "local") {
1056
1065
  await setLocalSkillEnabled(ctx.cwd, row.name, action.enabled);
1057
- await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。`);
1066
+ if ((await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。`)) === "reloaded")
1067
+ return;
1058
1068
  }
1059
1069
  else {
1060
1070
  const result = await setRecommendedSkillEnabled(ctx.cwd, row.id, action.enabled);
@@ -1068,7 +1078,8 @@ async function showSkillManager(pi, ctx) {
1068
1078
  ctx.ui.notify(result.message, "error");
1069
1079
  continue;
1070
1080
  }
1071
- await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"} ${row.name}。`);
1081
+ if ((await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"} ${row.name}。`)) === "reloaded")
1082
+ return;
1072
1083
  }
1073
1084
  }
1074
1085
  }
@@ -1502,6 +1513,16 @@ export default function psyclawExtension(pi) {
1502
1513
  });
1503
1514
  if (!legacyTestApi && typeof pi.on === "function")
1504
1515
  pi.on("tool_call", async (event, ctx) => {
1516
+ // Host-teardown hard block runs even without /init — project approvals do not cover this.
1517
+ const commandText = extractToolCommandText(event.toolName, event.input);
1518
+ if (commandText) {
1519
+ const hostOp = classifyIrreversibleHostCommand(commandText);
1520
+ if (hostOp) {
1521
+ const reason = irreversibleHostBlockReason(hostOp);
1522
+ ctx.ui.notify(reason, "error");
1523
+ return { block: true, terminate: true, reason };
1524
+ }
1525
+ }
1505
1526
  const run = await readActiveProject(ctx.cwd);
1506
1527
  if (!run || !toolNeedsApproval(event.toolName, event.input))
1507
1528
  return;