psyclaw 0.30.19 → 0.30.21

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.
Files changed (39) hide show
  1. package/dist/src/adapters/pi/extension.js +103 -9
  2. package/dist/src/adapters/pi/extension.js.map +1 -1
  3. package/dist/src/adapters/pi/observation-mask.d.ts +24 -0
  4. package/dist/src/adapters/pi/observation-mask.js +125 -0
  5. package/dist/src/adapters/pi/observation-mask.js.map +1 -0
  6. package/dist/src/analysis/runtime-tools.d.ts +29 -0
  7. package/dist/src/analysis/runtime-tools.js +379 -0
  8. package/dist/src/analysis/runtime-tools.js.map +1 -0
  9. package/dist/src/branding.js +1 -0
  10. package/dist/src/branding.js.map +1 -1
  11. package/dist/src/chat.d.ts +34 -0
  12. package/dist/src/chat.js +54 -45
  13. package/dist/src/chat.js.map +1 -1
  14. package/dist/src/cli.js +12 -0
  15. package/dist/src/cli.js.map +1 -1
  16. package/dist/src/headless/cli.d.ts +27 -0
  17. package/dist/src/headless/cli.js +259 -0
  18. package/dist/src/headless/cli.js.map +1 -0
  19. package/dist/src/headless/run.d.ts +69 -0
  20. package/dist/src/headless/run.js +172 -0
  21. package/dist/src/headless/run.js.map +1 -0
  22. package/dist/src/index.d.ts +2 -0
  23. package/dist/src/index.js +2 -0
  24. package/dist/src/index.js.map +1 -1
  25. package/dist/src/project/paths.js +1 -0
  26. package/dist/src/project/paths.js.map +1 -1
  27. package/dist/src/project/workspace.js +1 -0
  28. package/dist/src/project/workspace.js.map +1 -1
  29. package/dist/src/safety/data-access.d.ts +20 -0
  30. package/dist/src/safety/data-access.js +178 -0
  31. package/dist/src/safety/data-access.js.map +1 -0
  32. package/dist/src/safety/irreversible-host-ops.d.ts +22 -0
  33. package/dist/src/safety/irreversible-host-ops.js +71 -0
  34. package/dist/src/safety/irreversible-host-ops.js.map +1 -0
  35. package/dist/src/session/modes.js +2 -0
  36. package/dist/src/session/modes.js.map +1 -1
  37. package/dist/src/style/cli-ui.js +1 -0
  38. package/dist/src/style/cli-ui.js.map +1 -1
  39. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
1
  import { DefaultPackageManager, getAgentDir, SettingsManager } from "@earendil-works/pi-coding-agent";
2
+ import { maskToolObservations } from "./observation-mask.js";
3
+ import { registerAnalysisRuntimeTools } from "../../analysis/runtime-tools.js";
4
+ import { formatDataAccess, loadDataAccess, redactScriptOnlyOutput, scriptOnlyBlock, setDataAccess } from "../../safety/data-access.js";
2
5
  import { Type } from "typebox";
3
6
  import { appendApproval, approvalInputDigest, assertResearchDecision, bootstrapProject, ensureProjectBinding, hasCanonicalWorkspace, resolveResearchDecision, runInstitutionalFulltext, runLiteratureReview, runExpertReview, runAnalysisDelegation, runWritingReview, runMetaAnalysis, createStageRunner, exportAcademicDocument, recordCitationUse, runParallelPeerReview } from "../../index.js";
4
7
  import { runPlanWithPi } from "../../orchestration/pi-executor.js";
@@ -25,6 +28,7 @@ import { panelHub } from "../../panel/hub.js";
25
28
  import { appendChoiceRecord } from "../../research/choice.js";
26
29
  import { enabledLocalSkillPaths, enabledLocalPromptPaths, readUserSkillState, scanLocalSkills, setLocalSkillEnabled, setLocalSkillsEnabled, skillNamesInPaths, userSkillId, } from "../../skills/user-skills.js";
27
30
  import { RuntimeMcpRegistry, setUserMcpConfigEnabled, } from "../../integrations/mcp-runtime.js";
31
+ import { classifyIrreversibleHostCommand, extractToolCommandText, irreversibleHostBlockReason, } from "../../safety/irreversible-host-ops.js";
28
32
  import { SecretInputComponent, TextInputComponent, ProviderPickerComponent, } from "../../tui/provider-picker.js";
29
33
  import { resolveProviderBaseUrl } from "../../core/provider-endpoint.js";
30
34
  import { isArsPiActive, isArsPiTurn, psyclawArsPatch, setArsPiSessionActive, } from "../../ars/profile.js";
@@ -81,20 +85,25 @@ async function notifyError(ctx, error, extra = {}) {
81
85
  await captureAgentError(error, { phase: "extension", cwd: ctx.cwd, ...extra });
82
86
  ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
83
87
  }
84
- /** Reload Pi skills/prompts after enablement changes; fall back to asking for /reload. */
88
+ /**
89
+ * Reload Pi skills/prompts after enablement changes.
90
+ * Pi treats `ctx.reload()` as terminal for the current handler: notify first,
91
+ * then reload, and never use the old ctx afterward (`"reloaded"` = stop).
92
+ */
85
93
  async function notifyAfterSkillChange(ctx, summary, level = "info") {
86
94
  if (typeof ctx.reload === "function") {
87
95
  try {
96
+ ctx.ui.notify(`${summary}正在重新加载资源…`, level);
88
97
  await ctx.reload();
89
- ctx.ui.notify(`${summary}已自动重新加载。`, level);
90
- return;
98
+ return "reloaded";
91
99
  }
92
100
  catch (error) {
93
101
  ctx.ui.notify(`${summary}自动加载失败(${error instanceof Error ? error.message : String(error)})。请执行 /reload。`, "warning");
94
- return;
102
+ return "manual-reload";
95
103
  }
96
104
  }
97
105
  ctx.ui.notify(`${summary}请执行 /reload 重新加载。`, level);
106
+ return "manual-reload";
98
107
  }
99
108
  const activeAgentRuns = new Set();
100
109
  const CORE_SKILLS = new Set(["academic-grill", "research-intake", "evidence-capture", "citation-audit", "analysis-plan"]);
@@ -1025,9 +1034,11 @@ async function showSkillManager(pi, ctx) {
1025
1034
  const ids = locals.map((row) => row.name);
1026
1035
  await setLocalSkillsEnabled(ctx.cwd, ids, true);
1027
1036
  }
1028
- await notifyAfterSkillChange(ctx, failed.length > 0
1037
+ const outcome = await notifyAfterSkillChange(ctx, failed.length > 0
1029
1038
  ? `已启用其余可管理的 Skill(${failed.join("、")} 未启用:缺少 SKILL.md 或未通过校验,请在列表中单独安装或修复)。`
1030
1039
  : "已启用全部可管理的 Skill。", failed.length > 0 ? "warning" : "info");
1040
+ if (outcome === "reloaded")
1041
+ return;
1031
1042
  }
1032
1043
  else {
1033
1044
  for (const row of managed) {
@@ -1040,7 +1051,8 @@ async function showSkillManager(pi, ctx) {
1040
1051
  const ids = locals.map((row) => row.name);
1041
1052
  await setLocalSkillsEnabled(ctx.cwd, ids, false);
1042
1053
  }
1043
- await notifyAfterSkillChange(ctx, "已停用全部可管理的 Skill。");
1054
+ if ((await notifyAfterSkillChange(ctx, "已停用全部可管理的 Skill。")) === "reloaded")
1055
+ return;
1044
1056
  }
1045
1057
  continue;
1046
1058
  }
@@ -1054,7 +1066,8 @@ async function showSkillManager(pi, ctx) {
1054
1066
  if (action.type === "toggle") {
1055
1067
  if (row.source === "local") {
1056
1068
  await setLocalSkillEnabled(ctx.cwd, row.name, action.enabled);
1057
- await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。`);
1069
+ if ((await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"}本地 Skill ${row.name}。`)) === "reloaded")
1070
+ return;
1058
1071
  }
1059
1072
  else {
1060
1073
  const result = await setRecommendedSkillEnabled(ctx.cwd, row.id, action.enabled);
@@ -1068,7 +1081,8 @@ async function showSkillManager(pi, ctx) {
1068
1081
  ctx.ui.notify(result.message, "error");
1069
1082
  continue;
1070
1083
  }
1071
- await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"} ${row.name}。`);
1084
+ if ((await notifyAfterSkillChange(ctx, `已${action.enabled ? "启用" : "停用"} ${row.name}。`)) === "reloaded")
1085
+ return;
1072
1086
  }
1073
1087
  }
1074
1088
  }
@@ -1500,8 +1514,41 @@ export default function psyclawExtension(pi) {
1500
1514
  };
1501
1515
  }
1502
1516
  });
1517
+ if (!legacyTestApi && typeof pi.on === "function")
1518
+ pi.on("context", (event) => {
1519
+ const messages = maskToolObservations(event.messages);
1520
+ if (messages === event.messages)
1521
+ return;
1522
+ return { messages };
1523
+ });
1524
+ let dataAccessWarningShown = false;
1503
1525
  if (!legacyTestApi && typeof pi.on === "function")
1504
1526
  pi.on("tool_call", async (event, ctx) => {
1527
+ // Host-teardown hard block runs even without /init — project approvals do not cover this.
1528
+ const commandText = extractToolCommandText(event.toolName, event.input);
1529
+ if (commandText) {
1530
+ const hostOp = classifyIrreversibleHostCommand(commandText);
1531
+ if (hostOp) {
1532
+ const reason = irreversibleHostBlockReason(hostOp);
1533
+ ctx.ui.notify(reason, "error");
1534
+ return { block: true, terminate: true, reason };
1535
+ }
1536
+ }
1537
+ try {
1538
+ const access = await loadDataAccess(ctx.cwd);
1539
+ if (access.warning && !dataAccessWarningShown) {
1540
+ dataAccessWarningShown = true;
1541
+ ctx.ui.notify(access.warning, "warning");
1542
+ }
1543
+ const privacyReason = scriptOnlyBlock(event.toolName, event.input, access.entries, ctx.cwd);
1544
+ if (privacyReason) {
1545
+ ctx.ui.notify(privacyReason, "warning");
1546
+ return { block: true, reason: privacyReason };
1547
+ }
1548
+ }
1549
+ catch {
1550
+ // A broken checker must not take down unrelated tools. Defaults still apply on the next call.
1551
+ }
1505
1552
  const run = await readActiveProject(ctx.cwd);
1506
1553
  if (!run || !toolNeedsApproval(event.toolName, event.input))
1507
1554
  return;
@@ -1534,6 +1581,28 @@ export default function psyclawExtension(pi) {
1534
1581
  });
1535
1582
  return undefined;
1536
1583
  });
1584
+ if (!legacyTestApi && typeof pi.on === "function")
1585
+ pi.on("tool_result", async (event, ctx) => {
1586
+ try {
1587
+ const access = await loadDataAccess(ctx.cwd);
1588
+ let changed = false;
1589
+ const content = event.content.map((part) => {
1590
+ if (part.type !== "text")
1591
+ return part;
1592
+ const text = redactScriptOnlyOutput(part.text, access.entries);
1593
+ if (text === part.text)
1594
+ return part;
1595
+ changed = true;
1596
+ return { ...part, text };
1597
+ });
1598
+ if (!changed)
1599
+ return;
1600
+ return { content };
1601
+ }
1602
+ catch {
1603
+ return;
1604
+ }
1605
+ });
1537
1606
  pi.registerCommand("exit", {
1538
1607
  description: "完整退出 PsyClaw(等同 /quit)",
1539
1608
  handler: async (_args, ctx) => {
@@ -1558,7 +1627,8 @@ export default function psyclawExtension(pi) {
1558
1627
  }
1559
1628
  ctx.ui.notify([
1560
1629
  `工作仓库已初始化:${project.id}`,
1561
- "已创建 data/raw|clean、analysis/、literature/、paper/、psyclaw.md、.psyclaw/",
1630
+ "已创建 data/raw|clean|secret、analysis/、literature/、paper/、psyclaw.md、.psyclaw/",
1631
+ "data/secret 默认 script-only:模型不能直接读内容,分析脚本可以打开。/data-access 可改级别或指定其他文件。",
1562
1632
  "Shift+Tab:chat → analysis → academic",
1563
1633
  "Thinking:Ctrl+Shift+T",
1564
1634
  "澄清与分析请切到 analysis;写作审稿请切到 academic。输入 /help 查看速览。",
@@ -1569,6 +1639,29 @@ export default function psyclawExtension(pi) {
1569
1639
  }
1570
1640
  },
1571
1641
  });
1642
+ pi.registerCommand("data-access", {
1643
+ description: "查看或设置文件展示级别(full 或 script-only)",
1644
+ handler: async (args, ctx) => {
1645
+ try {
1646
+ const parts = args.trim().split(/\s+/).filter(Boolean);
1647
+ if (parts.length === 0) {
1648
+ const loaded = await loadDataAccess(ctx.cwd);
1649
+ ctx.ui.notify([formatDataAccess(loaded.entries), loaded.warning].filter(Boolean).join("\n"), loaded.warning ? "warning" : "info");
1650
+ return;
1651
+ }
1652
+ const access = parts.at(-1);
1653
+ if (parts[0] !== "set" || parts.length < 3 || (access !== "full" && access !== "script-only")) {
1654
+ ctx.ui.notify("用法:/data-access 或 /data-access set <相对路径> <full|script-only>", "error");
1655
+ return;
1656
+ }
1657
+ const entries = await setDataAccess(ctx.cwd, parts.slice(1, -1).join(" "), access);
1658
+ ctx.ui.notify(formatDataAccess(entries), "info");
1659
+ }
1660
+ catch (error) {
1661
+ await notifyError(ctx, error);
1662
+ }
1663
+ },
1664
+ });
1572
1665
  const handleCrosscheck = async (args, ctx) => {
1573
1666
  try {
1574
1667
  await ensureDefaultVerifyChecklist(ctx.cwd);
@@ -2100,6 +2193,7 @@ export default function psyclawExtension(pi) {
2100
2193
  },
2101
2194
  });
2102
2195
  if (typeof pi.registerTool === "function") {
2196
+ registerAnalysisRuntimeTools(pi);
2103
2197
  pi.registerTool({
2104
2198
  name: "psyclaw_research_decision",
2105
2199
  label: "Research decision",