psyclaw 0.30.20 → 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.
@@ -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";
@@ -1511,6 +1514,14 @@ export default function psyclawExtension(pi) {
1511
1514
  };
1512
1515
  }
1513
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;
1514
1525
  if (!legacyTestApi && typeof pi.on === "function")
1515
1526
  pi.on("tool_call", async (event, ctx) => {
1516
1527
  // Host-teardown hard block runs even without /init — project approvals do not cover this.
@@ -1523,6 +1534,21 @@ export default function psyclawExtension(pi) {
1523
1534
  return { block: true, terminate: true, reason };
1524
1535
  }
1525
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
+ }
1526
1552
  const run = await readActiveProject(ctx.cwd);
1527
1553
  if (!run || !toolNeedsApproval(event.toolName, event.input))
1528
1554
  return;
@@ -1555,6 +1581,28 @@ export default function psyclawExtension(pi) {
1555
1581
  });
1556
1582
  return undefined;
1557
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
+ });
1558
1606
  pi.registerCommand("exit", {
1559
1607
  description: "完整退出 PsyClaw(等同 /quit)",
1560
1608
  handler: async (_args, ctx) => {
@@ -1579,7 +1627,8 @@ export default function psyclawExtension(pi) {
1579
1627
  }
1580
1628
  ctx.ui.notify([
1581
1629
  `工作仓库已初始化:${project.id}`,
1582
- "已创建 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 可改级别或指定其他文件。",
1583
1632
  "Shift+Tab:chat → analysis → academic",
1584
1633
  "Thinking:Ctrl+Shift+T",
1585
1634
  "澄清与分析请切到 analysis;写作审稿请切到 academic。输入 /help 查看速览。",
@@ -1590,6 +1639,29 @@ export default function psyclawExtension(pi) {
1590
1639
  }
1591
1640
  },
1592
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
+ });
1593
1665
  const handleCrosscheck = async (args, ctx) => {
1594
1666
  try {
1595
1667
  await ensureDefaultVerifyChecklist(ctx.cwd);
@@ -2121,6 +2193,7 @@ export default function psyclawExtension(pi) {
2121
2193
  },
2122
2194
  });
2123
2195
  if (typeof pi.registerTool === "function") {
2196
+ registerAnalysisRuntimeTools(pi);
2124
2197
  pi.registerTool({
2125
2198
  name: "psyclaw_research_decision",
2126
2199
  label: "Research decision",