psyclaw 0.30.20 → 0.30.22
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/dist/src/adapters/pi/extension.js +90 -1
- package/dist/src/adapters/pi/extension.js.map +1 -1
- package/dist/src/adapters/pi/observation-mask.d.ts +41 -0
- package/dist/src/adapters/pi/observation-mask.js +226 -0
- package/dist/src/adapters/pi/observation-mask.js.map +1 -0
- package/dist/src/analysis/output-log.d.ts +5 -0
- package/dist/src/analysis/output-log.js +60 -0
- package/dist/src/analysis/output-log.js.map +1 -0
- package/dist/src/analysis/runtime-tools.d.ts +29 -0
- package/dist/src/analysis/runtime-tools.js +399 -0
- package/dist/src/analysis/runtime-tools.js.map +1 -0
- package/dist/src/project/paths.js +1 -0
- package/dist/src/project/paths.js.map +1 -1
- package/dist/src/project/workspace.js +1 -0
- package/dist/src/project/workspace.js.map +1 -1
- package/dist/src/safety/data-access.d.ts +22 -0
- package/dist/src/safety/data-access.js +189 -0
- package/dist/src/safety/data-access.js.map +1 -0
- package/dist/src/session/modes.js +2 -0
- package/dist/src/session/modes.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { DefaultPackageManager, getAgentDir, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { isObservationEvidence, maskToolObservationsStable, observationSettledLimit } from "./observation-mask.js";
|
|
3
|
+
import { outputLogFooter, persistToolOutput } from "../../analysis/output-log.js";
|
|
4
|
+
import { registerAnalysisRuntimeTools } from "../../analysis/runtime-tools.js";
|
|
5
|
+
import { formatDataAccess, loadDataAccess, redactScriptOnlyOutput, scriptOnlyBlock, setDataAccess } from "../../safety/data-access.js";
|
|
2
6
|
import { Type } from "typebox";
|
|
3
7
|
import { appendApproval, approvalInputDigest, assertResearchDecision, bootstrapProject, ensureProjectBinding, hasCanonicalWorkspace, resolveResearchDecision, runInstitutionalFulltext, runLiteratureReview, runExpertReview, runAnalysisDelegation, runWritingReview, runMetaAnalysis, createStageRunner, exportAcademicDocument, recordCitationUse, runParallelPeerReview } from "../../index.js";
|
|
4
8
|
import { runPlanWithPi } from "../../orchestration/pi-executor.js";
|
|
@@ -1511,6 +1515,14 @@ export default function psyclawExtension(pi) {
|
|
|
1511
1515
|
};
|
|
1512
1516
|
}
|
|
1513
1517
|
});
|
|
1518
|
+
if (!legacyTestApi && typeof pi.on === "function")
|
|
1519
|
+
pi.on("context", (event) => {
|
|
1520
|
+
const messages = maskToolObservationsStable(event.messages);
|
|
1521
|
+
if (messages === event.messages)
|
|
1522
|
+
return;
|
|
1523
|
+
return { messages };
|
|
1524
|
+
});
|
|
1525
|
+
let dataAccessWarningShown = false;
|
|
1514
1526
|
if (!legacyTestApi && typeof pi.on === "function")
|
|
1515
1527
|
pi.on("tool_call", async (event, ctx) => {
|
|
1516
1528
|
// Host-teardown hard block runs even without /init — project approvals do not cover this.
|
|
@@ -1523,6 +1535,21 @@ export default function psyclawExtension(pi) {
|
|
|
1523
1535
|
return { block: true, terminate: true, reason };
|
|
1524
1536
|
}
|
|
1525
1537
|
}
|
|
1538
|
+
try {
|
|
1539
|
+
const access = await loadDataAccess(ctx.cwd);
|
|
1540
|
+
if (access.warning && !dataAccessWarningShown) {
|
|
1541
|
+
dataAccessWarningShown = true;
|
|
1542
|
+
ctx.ui.notify(access.warning, "warning");
|
|
1543
|
+
}
|
|
1544
|
+
const privacyReason = scriptOnlyBlock(event.toolName, event.input, access.entries, ctx.cwd);
|
|
1545
|
+
if (privacyReason) {
|
|
1546
|
+
ctx.ui.notify(privacyReason, "warning");
|
|
1547
|
+
return { block: true, reason: privacyReason };
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
catch {
|
|
1551
|
+
// A broken checker must not take down unrelated tools. Defaults still apply on the next call.
|
|
1552
|
+
}
|
|
1526
1553
|
const run = await readActiveProject(ctx.cwd);
|
|
1527
1554
|
if (!run || !toolNeedsApproval(event.toolName, event.input))
|
|
1528
1555
|
return;
|
|
@@ -1555,6 +1582,43 @@ export default function psyclawExtension(pi) {
|
|
|
1555
1582
|
});
|
|
1556
1583
|
return undefined;
|
|
1557
1584
|
});
|
|
1585
|
+
if (!legacyTestApi && typeof pi.on === "function")
|
|
1586
|
+
pi.on("tool_result", async (event, ctx) => {
|
|
1587
|
+
try {
|
|
1588
|
+
const access = await loadDataAccess(ctx.cwd);
|
|
1589
|
+
let changed = false;
|
|
1590
|
+
const content = event.content.map((part) => {
|
|
1591
|
+
if (part.type !== "text")
|
|
1592
|
+
return part;
|
|
1593
|
+
const text = redactScriptOnlyOutput(part.text, access.entries);
|
|
1594
|
+
if (text === part.text)
|
|
1595
|
+
return part;
|
|
1596
|
+
changed = true;
|
|
1597
|
+
return { ...part, text };
|
|
1598
|
+
});
|
|
1599
|
+
if (!isObservationEvidence(event.toolName)) {
|
|
1600
|
+
const body = content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
1601
|
+
const saved = await persistToolOutput(ctx.cwd, event.toolCallId, body, observationSettledLimit());
|
|
1602
|
+
if (saved) {
|
|
1603
|
+
const footer = outputLogFooter(saved, body);
|
|
1604
|
+
for (let index = content.length - 1; index >= 0; index -= 1) {
|
|
1605
|
+
const part = content[index];
|
|
1606
|
+
if (part?.type !== "text")
|
|
1607
|
+
continue;
|
|
1608
|
+
content[index] = { ...part, text: `${part.text}\n${footer}` };
|
|
1609
|
+
changed = true;
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
if (!changed)
|
|
1615
|
+
return;
|
|
1616
|
+
return { content };
|
|
1617
|
+
}
|
|
1618
|
+
catch {
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1558
1622
|
pi.registerCommand("exit", {
|
|
1559
1623
|
description: "完整退出 PsyClaw(等同 /quit)",
|
|
1560
1624
|
handler: async (_args, ctx) => {
|
|
@@ -1579,7 +1643,8 @@ export default function psyclawExtension(pi) {
|
|
|
1579
1643
|
}
|
|
1580
1644
|
ctx.ui.notify([
|
|
1581
1645
|
`工作仓库已初始化:${project.id}`,
|
|
1582
|
-
"已创建 data/raw|clean、analysis/、literature/、paper/、psyclaw.md、.psyclaw/",
|
|
1646
|
+
"已创建 data/raw|clean|secret、analysis/、literature/、paper/、psyclaw.md、.psyclaw/",
|
|
1647
|
+
"data/secret 默认 script-only:模型不能直接读内容,分析脚本可以打开。/data-access 可改级别或指定其他文件。",
|
|
1583
1648
|
"Shift+Tab:chat → analysis → academic",
|
|
1584
1649
|
"Thinking:Ctrl+Shift+T",
|
|
1585
1650
|
"澄清与分析请切到 analysis;写作审稿请切到 academic。输入 /help 查看速览。",
|
|
@@ -1590,6 +1655,29 @@ export default function psyclawExtension(pi) {
|
|
|
1590
1655
|
}
|
|
1591
1656
|
},
|
|
1592
1657
|
});
|
|
1658
|
+
pi.registerCommand("data-access", {
|
|
1659
|
+
description: "查看或设置文件展示级别(full 或 script-only)",
|
|
1660
|
+
handler: async (args, ctx) => {
|
|
1661
|
+
try {
|
|
1662
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
1663
|
+
if (parts.length === 0) {
|
|
1664
|
+
const loaded = await loadDataAccess(ctx.cwd);
|
|
1665
|
+
ctx.ui.notify([formatDataAccess(loaded.entries), loaded.warning].filter(Boolean).join("\n"), loaded.warning ? "warning" : "info");
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
const access = parts.at(-1);
|
|
1669
|
+
if (parts[0] !== "set" || parts.length < 3 || (access !== "full" && access !== "script-only")) {
|
|
1670
|
+
ctx.ui.notify("用法:/data-access 或 /data-access set <相对路径> <full|script-only>", "error");
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
const entries = await setDataAccess(ctx.cwd, parts.slice(1, -1).join(" "), access);
|
|
1674
|
+
ctx.ui.notify(formatDataAccess(entries), "info");
|
|
1675
|
+
}
|
|
1676
|
+
catch (error) {
|
|
1677
|
+
await notifyError(ctx, error);
|
|
1678
|
+
}
|
|
1679
|
+
},
|
|
1680
|
+
});
|
|
1593
1681
|
const handleCrosscheck = async (args, ctx) => {
|
|
1594
1682
|
try {
|
|
1595
1683
|
await ensureDefaultVerifyChecklist(ctx.cwd);
|
|
@@ -2121,6 +2209,7 @@ export default function psyclawExtension(pi) {
|
|
|
2121
2209
|
},
|
|
2122
2210
|
});
|
|
2123
2211
|
if (typeof pi.registerTool === "function") {
|
|
2212
|
+
registerAnalysisRuntimeTools(pi);
|
|
2124
2213
|
pi.registerTool({
|
|
2125
2214
|
name: "psyclaw_research_decision",
|
|
2126
2215
|
label: "Research decision",
|