psyclaw 0.31.4 → 0.33.1
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 +70 -19
- package/dist/src/adapters/pi/extension.js.map +1 -1
- package/dist/src/adapters/pi/init-args.d.ts +16 -0
- package/dist/src/adapters/pi/init-args.js +40 -0
- package/dist/src/adapters/pi/init-args.js.map +1 -0
- package/dist/src/analysis/decision-points.d.ts +1 -1
- package/dist/src/analysis/decision-points.js +8 -1
- package/dist/src/analysis/decision-points.js.map +1 -1
- package/dist/src/analysis/prior/apply.d.ts +15 -0
- package/dist/src/analysis/prior/apply.js +98 -0
- package/dist/src/analysis/prior/apply.js.map +1 -0
- package/dist/src/analysis/prior/checks.d.ts +21 -0
- package/dist/src/analysis/prior/checks.js +233 -0
- package/dist/src/analysis/prior/checks.js.map +1 -0
- package/dist/src/analysis/prior/constants.d.ts +33 -0
- package/dist/src/analysis/prior/constants.js +117 -0
- package/dist/src/analysis/prior/constants.js.map +1 -0
- package/dist/src/analysis/prior/gate.d.ts +14 -0
- package/dist/src/analysis/prior/gate.js +93 -0
- package/dist/src/analysis/prior/gate.js.map +1 -0
- package/dist/src/analysis/prior/memory.d.ts +8 -0
- package/dist/src/analysis/prior/memory.js +46 -0
- package/dist/src/analysis/prior/memory.js.map +1 -0
- package/dist/src/analysis/prior/reflect.d.ts +6 -0
- package/dist/src/analysis/prior/reflect.js +48 -0
- package/dist/src/analysis/prior/reflect.js.map +1 -0
- package/dist/src/analysis/prior/render.d.ts +20 -0
- package/dist/src/analysis/prior/render.js +159 -0
- package/dist/src/analysis/prior/render.js.map +1 -0
- package/dist/src/analysis/prior/submit.d.ts +32 -0
- package/dist/src/analysis/prior/submit.js +213 -0
- package/dist/src/analysis/prior/submit.js.map +1 -0
- package/dist/src/analysis/prior/tools.d.ts +6 -0
- package/dist/src/analysis/prior/tools.js +38 -0
- package/dist/src/analysis/prior/tools.js.map +1 -0
- package/dist/src/ars/mode-editor.d.ts +1 -1
- package/dist/src/ars/mode-editor.js +1 -1
- package/dist/src/branding.js +3 -2
- package/dist/src/branding.js.map +1 -1
- package/dist/src/observability/langfuse.js +201 -5
- package/dist/src/observability/langfuse.js.map +1 -1
- package/dist/src/panel/server.js +1 -0
- package/dist/src/panel/server.js.map +1 -1
- package/dist/src/project/workspace.js +1 -1
- package/dist/src/project/workspace.js.map +1 -1
- package/dist/src/session/help.js +9 -3
- package/dist/src/session/help.js.map +1 -1
- package/dist/src/session/modes.d.ts +6 -2
- package/dist/src/session/modes.js +38 -2
- package/dist/src/session/modes.js.map +1 -1
- package/dist/src/skills/recommended.js +1 -0
- package/dist/src/skills/recommended.js.map +1 -1
- package/dist/src/style/cli-ui.js +1 -0
- package/dist/src/style/cli-ui.js.map +1 -1
- package/dist/src/updates/whats-new.js +15 -0
- package/dist/src/updates/whats-new.js.map +1 -1
- package/package.json +1 -1
- package/skills/core/analysis-plan/SKILL.md +1 -1
- package/skills/core/prior-plan/SKILL.md +53 -0
|
@@ -3,11 +3,16 @@ import { isInstructionResult, isObservationEvidence, maskToolObservationsStable,
|
|
|
3
3
|
import { outputLogFooter, persistToolOutput } from "../../analysis/output-log.js";
|
|
4
4
|
import { applyShellTimeout, isShellTimeout, SHELL_TIMEOUT_HINT, ShellClock } from "../../analysis/shell-timeout.js";
|
|
5
5
|
import { registerAnalysisRuntimeTools } from "../../analysis/runtime-tools.js";
|
|
6
|
+
import { priorToolBlock } from "../../analysis/prior/gate.js";
|
|
7
|
+
import { readPriorMemory } from "../../analysis/prior/memory.js";
|
|
8
|
+
import { priorApproved, priorPlanExists, priorRecallExists, recordPriorApproval } from "../../analysis/prior/submit.js";
|
|
9
|
+
import { registerPriorTools } from "../../analysis/prior/tools.js";
|
|
6
10
|
import { PSYCLAW_VERSION } from "../../branding.js";
|
|
7
11
|
import { takeWhatsNew } from "../../updates/whats-new.js";
|
|
8
12
|
import { formatDataAccess, loadDataAccess, redactScriptOnlyOutput, scriptOnlyBlock, setDataAccess } from "../../safety/data-access.js";
|
|
9
13
|
import { Type } from "typebox";
|
|
10
14
|
import { appendApproval, approvalInputDigest, assertResearchDecision, bootstrapProject, ensureProjectBinding, hasCanonicalWorkspace, resolveResearchDecision, runInstitutionalFulltext, runLiteratureReview, runExpertReview, runAnalysisDelegation, runWritingReview, runMetaAnalysis, createStageRunner, exportAcademicDocument, recordCitationUse, runParallelPeerReview } from "../../index.js";
|
|
15
|
+
import { parseInitArgs } from "./init-args.js";
|
|
11
16
|
import { runPlanWithPi } from "../../orchestration/pi-executor.js";
|
|
12
17
|
import { formatEffects, hasElevatedEffects, normalizeEffects, toolsForEffects } from "../../orchestration/effects.js";
|
|
13
18
|
import { agentManagerRows } from "../../agents/recommended-personas.js";
|
|
@@ -44,7 +49,7 @@ import { composeMethodInjection, injectedTopicsFor, readSkillPreferences, refere
|
|
|
44
49
|
import { formatAnalysisPlanTakeover, resolveStatsIntent, } from "../../analysis/stats-router.js";
|
|
45
50
|
import { arsRoot } from "../../ars/pi-panel-executor.js";
|
|
46
51
|
import { ArsModeEditor, isArsModeEditorText } from "../../ars/mode-editor.js";
|
|
47
|
-
import { MODE_STATUS, detectChatModeMismatch, formatChatModeMismatchNotice, nextSessionMode, parseSessionMode, sessionModePrompt, unattendedAnalysisPrompt, } from "../../session/modes.js";
|
|
52
|
+
import { MODE_STATUS, detectChatModeMismatch, formatChatModeMismatchNotice, nextSessionMode, parseSessionMode, analysisFollowsPriorPrompt, sessionModePrompt, unattendedAnalysisPrompt, unattendedPriorPrompt, } from "../../session/modes.js";
|
|
48
53
|
import { continuouslyWorkWarningText, isContinuouslyWorkEnabled, } from "../../session/continuously-work.js";
|
|
49
54
|
import { assertHumanVerifyGate, formatVerifyChecklist, isNaturalPlanConfirm, isPlanRitualConfirm, PLAN_RITUAL_PHRASE, ensureDefaultVerifyChecklist, loadVerifyChecklist, recordHumanVerification } from "../../verify/checklist.js";
|
|
50
55
|
import { formatSessionHelp, formatSessionHelpBrief } from "../../session/help.js";
|
|
@@ -80,13 +85,6 @@ async function emitPiTurnGeneration(generation, extras) {
|
|
|
80
85
|
});
|
|
81
86
|
return true;
|
|
82
87
|
}
|
|
83
|
-
/** Codex-style slash surface: bare command, or command + trailing free text. No subcommand trees. */
|
|
84
|
-
function parseInitArgs(args) {
|
|
85
|
-
const goal = args.trim();
|
|
86
|
-
if (!goal)
|
|
87
|
-
return {};
|
|
88
|
-
return { paradigm: "survey-observational", goal };
|
|
89
|
-
}
|
|
90
88
|
async function notifyError(ctx, error, extra = {}) {
|
|
91
89
|
await captureAgentError(error, { phase: "extension", cwd: ctx.cwd, ...extra });
|
|
92
90
|
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
@@ -112,7 +110,7 @@ async function notifyAfterSkillChange(ctx, summary, level = "info") {
|
|
|
112
110
|
return "manual-reload";
|
|
113
111
|
}
|
|
114
112
|
const activeAgentRuns = new Set();
|
|
115
|
-
const CORE_SKILLS = new Set(["academic-grill", "research-intake", "evidence-capture", "citation-audit", "analysis-plan"]);
|
|
113
|
+
const CORE_SKILLS = new Set(["academic-grill", "research-intake", "evidence-capture", "citation-audit", "analysis-plan", "prior-plan"]);
|
|
116
114
|
function findLastMatching(items, predicate) {
|
|
117
115
|
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
118
116
|
const item = items[index];
|
|
@@ -1228,7 +1226,7 @@ export default function psyclawExtension(pi) {
|
|
|
1228
1226
|
};
|
|
1229
1227
|
if (!legacyTestApi && typeof pi.registerShortcut === "function") {
|
|
1230
1228
|
pi.registerShortcut("shift+tab", {
|
|
1231
|
-
description: "Cycle chat → analysis → academic",
|
|
1229
|
+
description: "Cycle chat → analysis → academic → prior",
|
|
1232
1230
|
handler: () => {
|
|
1233
1231
|
cycleSessionMode();
|
|
1234
1232
|
},
|
|
@@ -1312,12 +1310,22 @@ export default function psyclawExtension(pi) {
|
|
|
1312
1310
|
return { systemPrompt: `${event.systemPrompt}\n\n${prompt}` };
|
|
1313
1311
|
});
|
|
1314
1312
|
if (!legacyTestApi && typeof pi.on === "function")
|
|
1315
|
-
pi.on("before_agent_start", (event, ctx) => {
|
|
1313
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
1316
1314
|
const restored = restoreSessionMode(ctx?.sessionManager);
|
|
1317
1315
|
sessionMode = restored;
|
|
1318
|
-
const
|
|
1319
|
-
?
|
|
1320
|
-
:
|
|
1316
|
+
const priorMemory = restored === "chat" || restored === "analysis"
|
|
1317
|
+
? await readPriorMemory(ctx?.cwd ?? process.cwd())
|
|
1318
|
+
: "";
|
|
1319
|
+
let modeBlock = sessionModePrompt(restored);
|
|
1320
|
+
if (restored === "analysis" && ctx && !ctx.hasUI)
|
|
1321
|
+
modeBlock = `${modeBlock}\n\n${unattendedAnalysisPrompt()}`;
|
|
1322
|
+
if (restored === "prior" && ctx && !ctx.hasUI)
|
|
1323
|
+
modeBlock = `${modeBlock}\n\n${unattendedPriorPrompt()}`;
|
|
1324
|
+
if (priorMemory && restored === "chat") {
|
|
1325
|
+
modeBlock = `## PsyClaw mode: chat\nPlain assistant on the Pi harness. Follow the prior plan memory below for later analysis. Do not ask for a mode switch.\n\n${priorMemory}`;
|
|
1326
|
+
}
|
|
1327
|
+
if (priorMemory && restored === "analysis")
|
|
1328
|
+
modeBlock = `${modeBlock}\n\n${analysisFollowsPriorPrompt(priorMemory)}`;
|
|
1321
1329
|
if (restored === "academic" || isArsPiTurn(event.systemPrompt) || isArsPiActive(ctx?.sessionManager)) {
|
|
1322
1330
|
return {
|
|
1323
1331
|
systemPrompt: `${event.systemPrompt}\n\n${modeBlock}\n\n${psyclawArsPatch({
|
|
@@ -1437,6 +1445,24 @@ export default function psyclawExtension(pi) {
|
|
|
1437
1445
|
};
|
|
1438
1446
|
}
|
|
1439
1447
|
}
|
|
1448
|
+
if (mode === "prior" && isPlanRitualConfirm(trimmed)) {
|
|
1449
|
+
const result = await recordPriorApproval(ctx.cwd);
|
|
1450
|
+
if (result.handoff)
|
|
1451
|
+
applySessionMode("chat");
|
|
1452
|
+
ctx.ui.notify(!result.handoff
|
|
1453
|
+
? result.message
|
|
1454
|
+
: result.runFailed
|
|
1455
|
+
? "脚本已按确认结果改好,但执行失败。报错末尾在对话里,完整日志没有放进来。"
|
|
1456
|
+
: "脚本已按确认结果改好并执行。当前是普通对话,可以使用 skill。", result.ok && !result.runFailed ? "info" : "warning");
|
|
1457
|
+
return {
|
|
1458
|
+
action: "transform",
|
|
1459
|
+
text: !result.handoff
|
|
1460
|
+
? `User typed the approval phrase, but the prior plan is not ready. ${result.message} Do not execute.`
|
|
1461
|
+
: result.runFailed
|
|
1462
|
+
? result.message
|
|
1463
|
+
: `User approved the prior plan ("${PLAN_RITUAL_PHRASE}"). The script was updated from the confirmed choices and has already been run. ${result.message} The session is now plain chat. Skills may be used. Do not ask to switch modes and do not run the script again unless the researcher asks.`,
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1440
1466
|
// Plan confirmations: soft「可以」= per-node / method acknowledge; ritual phrase = authorize execute.
|
|
1441
1467
|
if (mode === "analysis" && (isPlanRitualConfirm(trimmed) || isNaturalPlanConfirm(trimmed))) {
|
|
1442
1468
|
const plan = await readActiveAnalysisPlan(ctx.cwd);
|
|
@@ -1630,6 +1656,22 @@ export default function psyclawExtension(pi) {
|
|
|
1630
1656
|
catch {
|
|
1631
1657
|
// A broken checker must not take down unrelated tools. Defaults still apply on the next call.
|
|
1632
1658
|
}
|
|
1659
|
+
if (sessionMode === "prior") {
|
|
1660
|
+
try {
|
|
1661
|
+
const priorReason = priorToolBlock(sessionMode, event.toolName, event.input, {
|
|
1662
|
+
recallReady: await priorRecallExists(ctx.cwd),
|
|
1663
|
+
planReady: await priorPlanExists(ctx.cwd),
|
|
1664
|
+
approved: await priorApproved(ctx.cwd),
|
|
1665
|
+
});
|
|
1666
|
+
if (priorReason) {
|
|
1667
|
+
ctx.ui.notify(priorReason, "warning");
|
|
1668
|
+
return { block: true, reason: priorReason };
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
catch {
|
|
1672
|
+
// A broken prior gate must not take down unrelated tools.
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1633
1675
|
const run = await readActiveProject(ctx.cwd);
|
|
1634
1676
|
if (!run || !toolNeedsApproval(event.toolName, event.input))
|
|
1635
1677
|
return;
|
|
@@ -1723,14 +1765,22 @@ export default function psyclawExtension(pi) {
|
|
|
1723
1765
|
handler: async (args, ctx) => {
|
|
1724
1766
|
try {
|
|
1725
1767
|
const parsed = parseInitArgs(args);
|
|
1768
|
+
if (!parsed.ok) {
|
|
1769
|
+
ctx.ui.notify(parsed.message, "error");
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1726
1772
|
const already = await hasCanonicalWorkspace(ctx.cwd);
|
|
1727
1773
|
const hadProject = Boolean(await readActiveProject(ctx.cwd).catch(() => null));
|
|
1728
|
-
const project = await bootstrapProject({
|
|
1774
|
+
const project = await bootstrapProject({
|
|
1775
|
+
root: ctx.cwd,
|
|
1776
|
+
...(parsed.goal === undefined ? {} : { goal: parsed.goal }),
|
|
1777
|
+
...(parsed.paradigm === undefined ? {} : { paradigm: parsed.paradigm }),
|
|
1778
|
+
});
|
|
1729
1779
|
if (already || hadProject) {
|
|
1730
1780
|
ctx.ui.notify([
|
|
1731
1781
|
`已检测到既有工作区,无需重新建仓:${project.id}`,
|
|
1732
1782
|
"规范目录与 psyclaw.md 已存在;跨会话可直接继续 analysis / academic。",
|
|
1733
|
-
"Shift+Tab:chat → analysis → academic · 输入 /help 查看速览。",
|
|
1783
|
+
"Shift+Tab:chat → analysis → academic → prior · 输入 /help 查看速览。",
|
|
1734
1784
|
].join("\n"), "info");
|
|
1735
1785
|
return;
|
|
1736
1786
|
}
|
|
@@ -1738,9 +1788,9 @@ export default function psyclawExtension(pi) {
|
|
|
1738
1788
|
`工作仓库已初始化:${project.id}`,
|
|
1739
1789
|
"已创建 data/raw|clean|secret、analysis/、literature/、paper/、psyclaw.md、.psyclaw/",
|
|
1740
1790
|
"data/secret 默认 script-only:模型不能直接读内容,分析脚本可以打开。/data-access 可改级别或指定其他文件。",
|
|
1741
|
-
"Shift+Tab:chat → analysis → academic",
|
|
1791
|
+
"Shift+Tab:chat → analysis → academic → prior",
|
|
1742
1792
|
"Thinking:Ctrl+Shift+T",
|
|
1743
|
-
"
|
|
1793
|
+
"prior 先回忆再出方案,确认后直接跑脚本并回到普通对话;analysis 仍可直接跑数;写作审稿切到 academic。输入 /help 查看速览。",
|
|
1744
1794
|
].join("\n"), "info");
|
|
1745
1795
|
}
|
|
1746
1796
|
catch (error) {
|
|
@@ -2322,6 +2372,7 @@ export default function psyclawExtension(pi) {
|
|
|
2322
2372
|
});
|
|
2323
2373
|
if (typeof pi.registerTool === "function") {
|
|
2324
2374
|
registerAnalysisRuntimeTools(pi);
|
|
2375
|
+
registerPriorTools(pi, () => sessionMode);
|
|
2325
2376
|
pi.registerTool({
|
|
2326
2377
|
name: "psyclaw_research_decision",
|
|
2327
2378
|
label: "Research decision",
|
|
@@ -2605,7 +2656,7 @@ export default function psyclawExtension(pi) {
|
|
|
2605
2656
|
label: "Research skill",
|
|
2606
2657
|
description: "Load one trusted bundled psyclaw core skill and make its use visible to the user. Use this instead of directly reading a core SKILL.md file.",
|
|
2607
2658
|
parameters: Type.Object({
|
|
2608
|
-
name: Type.String({ description: "Core skill name: academic-grill, research-intake, evidence-capture, citation-audit, or
|
|
2659
|
+
name: Type.String({ description: "Core skill name: academic-grill, research-intake, evidence-capture, citation-audit, analysis-plan, or prior-plan" }),
|
|
2609
2660
|
purpose: Type.Optional(Type.String({ description: "Short user-facing reason for using this skill now" })),
|
|
2610
2661
|
}),
|
|
2611
2662
|
executionMode: "sequential",
|