psyclaw 0.31.5 → 0.34.0-preview.2

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 (151) hide show
  1. package/dist/apps/panel/index.html +16 -16
  2. package/dist/src/adapters/pi/arg-repair.d.ts +27 -0
  3. package/dist/src/adapters/pi/arg-repair.js +177 -0
  4. package/dist/src/adapters/pi/arg-repair.js.map +1 -0
  5. package/dist/src/adapters/pi/extension.js +1499 -493
  6. package/dist/src/adapters/pi/extension.js.map +1 -1
  7. package/dist/src/adapters/pi/observation-mask.d.ts +19 -0
  8. package/dist/src/adapters/pi/observation-mask.js +105 -2
  9. package/dist/src/adapters/pi/observation-mask.js.map +1 -1
  10. package/dist/src/adapters/pi/session.js +1 -1
  11. package/dist/src/adapters/pi/session.js.map +1 -1
  12. package/dist/src/analysis/decision-points.d.ts +4 -9
  13. package/dist/src/analysis/decision-points.js +20 -67
  14. package/dist/src/analysis/decision-points.js.map +1 -1
  15. package/dist/src/analysis/estimand.d.ts +127 -0
  16. package/dist/src/analysis/estimand.js +526 -0
  17. package/dist/src/analysis/estimand.js.map +1 -0
  18. package/dist/src/analysis/method-rules.d.ts +6 -0
  19. package/dist/src/analysis/method-rules.js +20 -3
  20. package/dist/src/analysis/method-rules.js.map +1 -1
  21. package/dist/src/analysis/package-net.d.ts +106 -0
  22. package/dist/src/analysis/package-net.js +277 -0
  23. package/dist/src/analysis/package-net.js.map +1 -0
  24. package/dist/src/analysis/plan.d.ts +6 -2
  25. package/dist/src/analysis/plan.js +34 -17
  26. package/dist/src/analysis/plan.js.map +1 -1
  27. package/dist/src/analysis/runtime-tools.d.ts +0 -6
  28. package/dist/src/analysis/runtime-tools.js +0 -156
  29. package/dist/src/analysis/runtime-tools.js.map +1 -1
  30. package/dist/src/analysis/shell-timeout.d.ts +21 -0
  31. package/dist/src/analysis/shell-timeout.js +87 -1
  32. package/dist/src/analysis/shell-timeout.js.map +1 -1
  33. package/dist/src/analysis/stats-router.d.ts +4 -8
  34. package/dist/src/analysis/stats-router.js +21 -23
  35. package/dist/src/analysis/stats-router.js.map +1 -1
  36. package/dist/src/ars/academic-router.d.ts +8 -8
  37. package/dist/src/ars/academic-router.js +22 -35
  38. package/dist/src/ars/academic-router.js.map +1 -1
  39. package/dist/src/ars/doctor.js +1 -2
  40. package/dist/src/ars/doctor.js.map +1 -1
  41. package/dist/src/ars/mode-editor.d.ts +7 -2
  42. package/dist/src/ars/mode-editor.js +15 -16
  43. package/dist/src/ars/mode-editor.js.map +1 -1
  44. package/dist/src/branding.d.ts +10 -0
  45. package/dist/src/branding.js +40 -32
  46. package/dist/src/branding.js.map +1 -1
  47. package/dist/src/chat.d.ts +1 -1
  48. package/dist/src/chat.js +12 -2
  49. package/dist/src/chat.js.map +1 -1
  50. package/dist/src/index.d.ts +1 -2
  51. package/dist/src/index.js +1 -2
  52. package/dist/src/index.js.map +1 -1
  53. package/dist/src/install/installer.js +0 -5
  54. package/dist/src/install/installer.js.map +1 -1
  55. package/dist/src/integrations/mcp-format.d.ts +6 -0
  56. package/dist/src/integrations/mcp-format.js +52 -0
  57. package/dist/src/integrations/mcp-format.js.map +1 -0
  58. package/dist/src/observability/langfuse.js +201 -5
  59. package/dist/src/observability/langfuse.js.map +1 -1
  60. package/dist/src/orchestration/research-agents.js +1 -1
  61. package/dist/src/orchestration/research-agents.js.map +1 -1
  62. package/dist/src/orchestration/runner.d.ts +0 -1
  63. package/dist/src/orchestration/runner.js +0 -3
  64. package/dist/src/orchestration/runner.js.map +1 -1
  65. package/dist/src/orchestration/scheduler.js +0 -31
  66. package/dist/src/orchestration/scheduler.js.map +1 -1
  67. package/dist/src/panel/server.js +3 -3
  68. package/dist/src/panel/server.js.map +1 -1
  69. package/dist/src/project/hitl.js +3 -3
  70. package/dist/src/project/hitl.js.map +1 -1
  71. package/dist/src/project/workspace.js +8 -20
  72. package/dist/src/project/workspace.js.map +1 -1
  73. package/dist/src/research/decisions.d.ts +115 -0
  74. package/dist/src/research/decisions.js +284 -0
  75. package/dist/src/research/decisions.js.map +1 -0
  76. package/dist/src/research/intent.d.ts +90 -0
  77. package/dist/src/research/intent.js +175 -0
  78. package/dist/src/research/intent.js.map +1 -0
  79. package/dist/src/research/plan-message.d.ts +117 -0
  80. package/dist/src/research/plan-message.js +187 -0
  81. package/dist/src/research/plan-message.js.map +1 -0
  82. package/dist/src/research/practice.d.ts +33 -0
  83. package/dist/src/research/practice.js +160 -0
  84. package/dist/src/research/practice.js.map +1 -0
  85. package/dist/src/router/decision-model.d.ts +54 -0
  86. package/dist/src/router/decision-model.js +129 -0
  87. package/dist/src/router/decision-model.js.map +1 -0
  88. package/dist/src/rules/user-rules.js.map +1 -1
  89. package/dist/src/safety/data-access.js +4 -4
  90. package/dist/src/safety/data-access.js.map +1 -1
  91. package/dist/src/safety/secret-marks.d.ts +44 -0
  92. package/dist/src/safety/secret-marks.js +88 -0
  93. package/dist/src/safety/secret-marks.js.map +1 -0
  94. package/dist/src/session/continuously-work.js +1 -1
  95. package/dist/src/session/continuously-work.js.map +1 -1
  96. package/dist/src/session/help.js +29 -32
  97. package/dist/src/session/help.js.map +1 -1
  98. package/dist/src/session/modes.d.ts +24 -17
  99. package/dist/src/session/modes.js +81 -94
  100. package/dist/src/session/modes.js.map +1 -1
  101. package/dist/src/session/skill-invoke.d.ts +54 -0
  102. package/dist/src/session/skill-invoke.js +177 -0
  103. package/dist/src/session/skill-invoke.js.map +1 -0
  104. package/dist/src/session/skill-reference.d.ts +15 -0
  105. package/dist/src/session/skill-reference.js +35 -0
  106. package/dist/src/session/skill-reference.js.map +1 -0
  107. package/dist/src/skills/recommended.js +0 -1
  108. package/dist/src/skills/recommended.js.map +1 -1
  109. package/dist/src/skills/user-skills.js +11 -0
  110. package/dist/src/skills/user-skills.js.map +1 -1
  111. package/dist/src/style/cli-ui.js +15 -12
  112. package/dist/src/style/cli-ui.js.map +1 -1
  113. package/dist/src/tui/biosignal-wizard.js +1 -1
  114. package/dist/src/tui/biosignal-wizard.js.map +1 -1
  115. package/dist/src/tui/wake-options.d.ts +2 -2
  116. package/dist/src/tui/wake-options.js +8 -5
  117. package/dist/src/tui/wake-options.js.map +1 -1
  118. package/dist/src/updates/check.js +4 -2
  119. package/dist/src/updates/check.js.map +1 -1
  120. package/dist/src/updates/registry.d.ts +2 -1
  121. package/dist/src/updates/registry.js +2 -2
  122. package/dist/src/updates/registry.js.map +1 -1
  123. package/dist/src/updates/status.d.ts +9 -2
  124. package/dist/src/updates/status.js +43 -6
  125. package/dist/src/updates/status.js.map +1 -1
  126. package/dist/src/updates/update.js +7 -3
  127. package/dist/src/updates/update.js.map +1 -1
  128. package/dist/src/updates/whats-new.js +12 -0
  129. package/dist/src/updates/whats-new.js.map +1 -1
  130. package/dist/src/verify/checklist.d.ts +1 -1
  131. package/dist/src/verify/checklist.js +5 -5
  132. package/dist/src/verify/checklist.js.map +1 -1
  133. package/dist/src/wake-options/runtime.d.ts +9 -0
  134. package/dist/src/wake-options/runtime.js +39 -1
  135. package/dist/src/wake-options/runtime.js.map +1 -1
  136. package/dist/src/workflows/academic-export.js.map +1 -1
  137. package/dist/src/workflows/meta-analysis.js +1 -1
  138. package/dist/src/workflows/meta-analysis.js.map +1 -1
  139. package/package.json +2 -1
  140. package/skills/core/academic-grill/SKILL.md +3 -3
  141. package/skills/core/analysis-plan/SKILL.md +35 -32
  142. package/skills/core/manifest.json +12 -4
  143. package/skills/core/package-install/SKILL.md +35 -0
  144. package/skills/core/package-install/pkgnet.py +178 -0
  145. package/skills/recommended/mcp-catalog.json +1 -1
  146. package/dist/src/research/choice.d.ts +0 -16
  147. package/dist/src/research/choice.js +0 -25
  148. package/dist/src/research/choice.js.map +0 -1
  149. package/dist/src/skills/registry.d.ts +0 -28
  150. package/dist/src/skills/registry.js +0 -550
  151. package/dist/src/skills/registry.js.map +0 -1
@@ -0,0 +1,175 @@
1
+ /**
2
+ * The researcher's intent, kept in the project: `.psyclaw/intent.jsonl` (design 11-29, A1–A2).
3
+ *
4
+ * Three kinds of line:
5
+ * - "said": a message the researcher wrote, word for word (recorded by the input hook in research mode);
6
+ * - "restated": the analyst's reading of that intent, item by item, each item quoting the researcher or
7
+ * the materials, or marked as inferred; code renders it into one message for the researcher;
8
+ * - "confirmed": the researcher's reply that confirms (or corrects) a restated version.
9
+ *
10
+ * The plan is checked against this record, not against a summary of the conversation, and the record
11
+ * outlives the conversation (a new session reads it back).
12
+ */
13
+ import { appendJsonl, readJsonl } from "../project/jsonl.js";
14
+ import { assertSafeProjectPath } from "../project/paths.js";
15
+ import { norm, quoteFound } from "../analysis/estimand.js";
16
+ export const INTENT_SCHEMA = "psyclaw/intent/v1";
17
+ export const INTENT_PATH = ".psyclaw/intent.jsonl";
18
+ export const INTENT_FIELDS = ["question", "outcome", "approach", "hypothesis", "data", "scope"];
19
+ export const FIELD_ZH = {
20
+ question: "研究问题",
21
+ outcome: "主要看的结果",
22
+ approach: "你原本打算怎么分析",
23
+ hypothesis: "假设与预测",
24
+ data: "数据与样本",
25
+ scope: "范围(要做和不做的)",
26
+ };
27
+ export const FLOW_ZH = {
28
+ theory: "理论驱动(研究 → 分析 → 写作):先定假设和预测,再用数据检验",
29
+ data: "数据驱动(分析 → 研究 → 写作):先探索数据,再用文献解释,写成探索性研究",
30
+ };
31
+ /**
32
+ * A quote is the researcher's or the materials' words unchanged. Chinese phrases are short, so an exact
33
+ * match of at least 4 characters counts here, besides the estimand rule (longer fragments, ellipses).
34
+ */
35
+ export function quoted(quote, source) {
36
+ const q = norm(quote);
37
+ return (q.length >= 4 && norm(source).includes(q)) || quoteFound(quote, source);
38
+ }
39
+ async function intentPath(root) {
40
+ return assertSafeProjectPath(root, INTENT_PATH);
41
+ }
42
+ export async function readIntentEvents(root) {
43
+ try {
44
+ return (await readJsonl(await intentPath(root))).filter((e) => e?.schemaVersion === INTENT_SCHEMA);
45
+ }
46
+ catch {
47
+ return [];
48
+ }
49
+ }
50
+ export function foldIntent(events) {
51
+ const state = { said: [], versions: 0 };
52
+ for (const e of events) {
53
+ if (e.event === "said")
54
+ state.said.push({ at: e.at, text: e.text });
55
+ else if (e.event === "restated") {
56
+ state.current = { version: e.version, at: e.at, items: e.items, ...(e.flow ? { flow: e.flow } : {}) };
57
+ state.versions = Math.max(state.versions, e.version);
58
+ }
59
+ else if (e.event === "confirmed" && state.current?.version === e.version) {
60
+ state.current.confirmed = { at: e.at, quote: e.quote, ...(e.corrections ? { corrections: e.corrections } : {}) };
61
+ }
62
+ }
63
+ return state;
64
+ }
65
+ export async function readIntent(root) {
66
+ return foldIntent(await readIntentEvents(root));
67
+ }
68
+ /** Record one message of the researcher, unchanged. Empty, slash commands and PsyClaw's own notes are skipped. */
69
+ export async function recordSaid(root, text, at = new Date().toISOString()) {
70
+ const t = text.trim();
71
+ if (!t || t.startsWith("/") || t.startsWith("[psyclaw]"))
72
+ return false;
73
+ const events = await readIntentEvents(root);
74
+ const last = [...events].reverse().find((e) => e.event === "said");
75
+ if (last && last.event === "said" && last.text === t)
76
+ return false;
77
+ await appendJsonl(await intentPath(root), { schemaVersion: INTENT_SCHEMA, event: "said", at, text: t });
78
+ return true;
79
+ }
80
+ /**
81
+ * Check and record a restated intent. An item with a quote must be found word for word in the
82
+ * researcher's messages (source researcher) or the materials (source brief); an item without one is
83
+ * the analyst's inference and is shown apart. At least one research question is needed.
84
+ */
85
+ export async function restateIntent(root, input) {
86
+ const problems = [];
87
+ const items = [];
88
+ input.items.forEach((raw, i) => {
89
+ const field = raw.field;
90
+ const text = String(raw.text ?? "").trim();
91
+ const at = `item ${i + 1}${raw.label ? ` (${raw.label})` : ""}`;
92
+ if (!INTENT_FIELDS.includes(field)) {
93
+ problems.push(`${at}: field must be one of ${INTENT_FIELDS.join(", ")}.`);
94
+ return;
95
+ }
96
+ if (!text) {
97
+ problems.push(`${at}: text is empty.`);
98
+ return;
99
+ }
100
+ const quote = raw.quote?.trim();
101
+ let source = "inferred";
102
+ if (quote) {
103
+ if (quoted(quote, input.said))
104
+ source = "researcher";
105
+ else if (quoted(quote, input.materials))
106
+ source = "brief";
107
+ else {
108
+ problems.push(`${at}: the quote is not found word for word in the researcher's messages or the materials. Quote them exactly, or leave quote out (the item is then shown as your inference).`);
109
+ return;
110
+ }
111
+ }
112
+ items.push({ field, ...(raw.label?.trim() ? { label: raw.label.trim() } : {}), text, ...(quote ? { quote } : {}), source });
113
+ });
114
+ if (!problems.length && !items.some((x) => x.field === "question"))
115
+ problems.push("Give at least one research question (field question), in the researcher's words where they said it.");
116
+ if (input.flow && input.flow !== "theory" && input.flow !== "data")
117
+ problems.push("flow must be theory or data.");
118
+ if (problems.length)
119
+ return { version: 0, items, problems };
120
+ const state = await readIntent(root);
121
+ const version = state.versions + 1;
122
+ await appendJsonl(await intentPath(root), { schemaVersion: INTENT_SCHEMA, event: "restated", at: new Date().toISOString(), version, items, ...(input.flow ? { flow: input.flow } : {}) });
123
+ return { version, items, problems };
124
+ }
125
+ /** Record the researcher's reply that confirms the latest restated version (corrections, if any, in their words). */
126
+ export async function confirmIntent(root, quote, corrections) {
127
+ const q = quote.trim();
128
+ if (!q)
129
+ throw new Error("confirm needs quote: the researcher's reply, unchanged");
130
+ const state = await readIntent(root);
131
+ if (!state.current)
132
+ throw new Error("nothing to confirm: restate the intent first (psyclaw_intent action=restate)");
133
+ // A reply such as「对」is short: any part of a later message, word for word, is enough.
134
+ if (!state.said.some((s) => s.at >= state.current.at && norm(s.text).includes(norm(q)))) {
135
+ throw new Error("the quote is not found in a researcher message after the restated intent; quote their reply exactly");
136
+ }
137
+ await appendJsonl(await intentPath(root), {
138
+ schemaVersion: INTENT_SCHEMA, event: "confirmed", at: new Date().toISOString(), version: state.current.version, quote: q,
139
+ ...(corrections?.trim() ? { corrections: corrections.trim() } : {}),
140
+ });
141
+ return { version: state.current.version };
142
+ }
143
+ /** The restated intent as one message for the researcher. Inferred items are listed apart, so they get a look. */
144
+ export function renderIntent(items, flow) {
145
+ const lines = ["## 我理解的研究意图(请确认或改正)", ""];
146
+ const stated = items.filter((x) => x.source !== "inferred");
147
+ const inferred = items.filter((x) => x.source === "inferred");
148
+ const show = (x) => {
149
+ const label = x.label ? `${x.label}:` : "";
150
+ const basis = x.source === "researcher" ? `(你说:「${x.quote}」)` : x.source === "brief" ? `(材料:「${x.quote}」)` : "";
151
+ return `- ${label}${x.text}${basis}`;
152
+ };
153
+ for (const field of INTENT_FIELDS) {
154
+ const rows = stated.filter((x) => x.field === field);
155
+ if (!rows.length)
156
+ continue;
157
+ lines.push(`**${FIELD_ZH[field]}**`, ...rows.map(show), "");
158
+ }
159
+ if (inferred.length) {
160
+ lines.push("**这些是我推断的,你没有明说,请特别看一下**", ...inferred.map((x) => `- ${FIELD_ZH[x.field]}${x.label ? `(${x.label})` : ""}:${x.text}`), "");
161
+ }
162
+ if (flow)
163
+ lines.push(`**走的流程**:${FLOW_ZH[flow]}`, "");
164
+ lines.push("对就回复「对」;有不对或漏掉的,直接写出来。确认之后我再出分析方案。");
165
+ return lines.join("\n");
166
+ }
167
+ /** A short version for the system prompt and the start-of-session brief. */
168
+ export function intentBrief(state) {
169
+ if (!state.current)
170
+ return "";
171
+ const c = state.current;
172
+ const rows = c.items.map((x) => `- ${FIELD_ZH[x.field]}${x.label ? ` ${x.label}` : ""}:${x.text}${x.source === "inferred" ? "(推断)" : ""}`);
173
+ return [`研究意图 v${c.version}${c.confirmed ? "(研究者已确认)" : "(待研究者确认)"}${c.flow ? `,${c.flow === "theory" ? "理论驱动" : "数据驱动"}` : ""}:`, ...rows].join("\n");
174
+ }
175
+ //# sourceMappingURL=intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/research/intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE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,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzJ,CAAC"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The whole plan in one numbered message (research mode, 11-29).
3
+ *
4
+ * The old PsyClaw put every decision point into one text message (D1…Dn with options) and the
5
+ * researcher settled all of them in one reply. The 11-29 runs showed this beat one choice card
6
+ * per decision: fewer researcher turns, and the researcher's own words (including the analyses
7
+ * the plan missed) reach the plan. Code numbers the points and writes the message, so it is the
8
+ * same every time; the model posts it and waits. Cards are only for what the reply leaves unclear.
9
+ */
10
+ export type PointImpact = "key" | "intent" | "convention";
11
+ export interface PlanPoint {
12
+ rq?: string;
13
+ question: string;
14
+ options?: string[];
15
+ /** 1-based index of the recommended option. */
16
+ recommended?: number;
17
+ /** Who already settled it; open (default) goes to the researcher. researcher: they already said it (quote them). */
18
+ by?: "open" | "brief" | "analyst" | "researcher";
19
+ quote?: string;
20
+ reason?: string;
21
+ /**
22
+ * key: the choice changes the answer to a research question or the conclusion; intent: it depends on
23
+ * what the researcher wants; convention: the field settles it. Default: open → intent, else convention.
24
+ */
25
+ impact?: PointImpact;
26
+ /** key points: one line on what changes depending on the choice. */
27
+ why?: string;
28
+ }
29
+ export interface NumberedPoint extends PlanPoint {
30
+ n: number;
31
+ /** Decision-record id: <planId>:D<n>. */
32
+ id: string;
33
+ open: boolean;
34
+ impact: PointImpact;
35
+ /** Submitted as settled by the analyst, but it is a research-intent decision: put to the researcher. */
36
+ promoted?: boolean;
37
+ }
38
+ export declare const pointId: (planId: string, n: number) => string;
39
+ export declare const isPlanPointId: (id: string) => boolean;
40
+ export declare const pointLabel: (id: string) => string;
41
+ /** Key decisions shown in full at once: working memory holds about four chunks (Cowan, 2001). */
42
+ export declare const MAX_KEY = 4;
43
+ /** Options per open decision: decision time grows with the number of options (Hick–Hyman). */
44
+ export declare const MAX_OPTIONS = 3;
45
+ /**
46
+ * Decisions settled by the researcher's intent, not by convention (the 11-28 list: sample rules, coding
47
+ * and scoring, missing data, model specification, inference and decision rules, plus the primary outcome).
48
+ * Alpha and sidedness are not in it: they are declarations settled as a stated convention (11-09).
49
+ * The 11-29 run on paper 72 settled 13 of 17 points "by analyst", among them which outcome is primary,
50
+ * the sign coding and the verdict rules. Only ever promotes a point to the researcher.
51
+ */
52
+ export declare const INTENT_PATTERN: RegExp;
53
+ /**
54
+ * Numbers the points. A point is open unless the brief settles it (with a quote) or it is a convention the
55
+ * analyst settles (with a reason). The analyst cannot settle a research-intent decision: one marked key or
56
+ * intent, one that matches INTENT_PATTERN, or one in `promote` (the decision model's judgement, by index)
57
+ * is put to the researcher with the analyst's choice as the recommendation. Open points need 2–3 options;
58
+ * key points need `why`. Points are numbered key first, then the other open ones, then the settled ones.
59
+ */
60
+ export declare function numberPoints(planId: string, points: PlanPoint[], promote?: ReadonlySet<number>): {
61
+ points: NumberedPoint[];
62
+ problems: string[];
63
+ promoted: string[];
64
+ };
65
+ /** The first sentence or line of a long text, at most `max` characters (the goal row, not the whole brief). */
66
+ export declare function oneLine(text: string, max?: number): string;
67
+ export interface PlanSummary {
68
+ goal?: string;
69
+ primaryOutcome?: string;
70
+ primaryAnalysis?: string;
71
+ proposedMethods?: string[];
72
+ exploratoryAnalyses?: string[];
73
+ missingDataPlan?: string;
74
+ multiplicityPlan?: string;
75
+ exclusionCriteria?: string;
76
+ }
77
+ export interface AgentAddition {
78
+ analysis: string;
79
+ reason: string;
80
+ }
81
+ /**
82
+ * The message for the researcher, in four blocks by what they need to do (design 11-29, A3–A4):
83
+ * 1. key decisions (at most MAX_KEY, in full, each with what changes);
84
+ * 2. the other open decisions, one line each with the recommendation;
85
+ * 3. analyses the analyst adds beyond the request, with the reason;
86
+ * 4. what the materials or conventions settle, one line each, open to change.
87
+ */
88
+ export declare function renderPlanMessage(plan: PlanSummary, points: NumberedPoint[], additions?: AgentAddition[]): string;
89
+ export interface PointAnswer {
90
+ /** "D3" or the full id. */
91
+ d: string;
92
+ option?: number;
93
+ text?: string;
94
+ }
95
+ export interface SettleStep {
96
+ id: string;
97
+ choice: string;
98
+ /** Whether the researcher named this point; false = settled by their "all as recommended". */
99
+ named: boolean;
100
+ }
101
+ /**
102
+ * Turns the researcher's one reply (already read by the model into per-point answers) into
103
+ * decisions. Points the reply does not name take the recommendation when `rest` is
104
+ * "recommended"; otherwise they stay open. Returns the settlements and the points still open.
105
+ */
106
+ export declare function settleFromReply(open: Array<{
107
+ id: string;
108
+ question: string;
109
+ options: Array<{
110
+ label: string;
111
+ }>;
112
+ recommendation?: string;
113
+ }>, answers: PointAnswer[], rest: "recommended" | "open"): {
114
+ settle: SettleStep[];
115
+ left: string[];
116
+ problems: string[];
117
+ };
@@ -0,0 +1,187 @@
1
+ /**
2
+ * The whole plan in one numbered message (research mode, 11-29).
3
+ *
4
+ * The old PsyClaw put every decision point into one text message (D1…Dn with options) and the
5
+ * researcher settled all of them in one reply. The 11-29 runs showed this beat one choice card
6
+ * per decision: fewer researcher turns, and the researcher's own words (including the analyses
7
+ * the plan missed) reach the plan. Code numbers the points and writes the message, so it is the
8
+ * same every time; the model posts it and waits. Cards are only for what the reply leaves unclear.
9
+ */
10
+ export const pointId = (planId, n) => `${planId}:D${n}`;
11
+ export const isPlanPointId = (id) => /:D\d+$/.test(id);
12
+ export const pointLabel = (id) => id.replace(/^.*:(D\d+)$/, "$1");
13
+ /** Key decisions shown in full at once: working memory holds about four chunks (Cowan, 2001). */
14
+ export const MAX_KEY = 4;
15
+ /** Options per open decision: decision time grows with the number of options (Hick–Hyman). */
16
+ export const MAX_OPTIONS = 3;
17
+ /**
18
+ * Decisions settled by the researcher's intent, not by convention (the 11-28 list: sample rules, coding
19
+ * and scoring, missing data, model specification, inference and decision rules, plus the primary outcome).
20
+ * Alpha and sidedness are not in it: they are declarations settled as a stated convention (11-09).
21
+ * The 11-29 run on paper 72 settled 13 of 17 points "by analyst", among them which outcome is primary,
22
+ * the sign coding and the verdict rules. Only ever promotes a point to the researcher.
23
+ */
24
+ export const INTENT_PATTERN = /\b(primary|exclu|inclu|sample|respondents?|participants? (?:enter|included)|cod(?:e|es|ing)\b|scor(?:e|es|ing)|sign\b|direction|revers|covariat|control(?:s|ling)? for|adjust|model|estimator|missing|imput|threshold|verdict|counts? as support|multiplicity|subgroup|moderat|reference (?:group|category|level)|operationali[sz])|主要结果|主结果|排除|纳入|样本|计分|编码|方向|反向|协变量|控制|调整|模型|缺失|插补|阈值|判定|多重比较|亚组|调节|参照|操作化/i;
25
+ const TIER = { key: 0, intent: 1, convention: 2 };
26
+ /**
27
+ * Numbers the points. A point is open unless the brief settles it (with a quote) or it is a convention the
28
+ * analyst settles (with a reason). The analyst cannot settle a research-intent decision: one marked key or
29
+ * intent, one that matches INTENT_PATTERN, or one in `promote` (the decision model's judgement, by index)
30
+ * is put to the researcher with the analyst's choice as the recommendation. Open points need 2–3 options;
31
+ * key points need `why`. Points are numbered key first, then the other open ones, then the settled ones.
32
+ */
33
+ export function numberPoints(planId, points, promote = new Set()) {
34
+ const problems = [];
35
+ const staged = [];
36
+ points.forEach((p, i) => {
37
+ const at = `point ${i + 1}`;
38
+ const question = String(p.question ?? "").trim();
39
+ if (!question) {
40
+ problems.push(`${at}: no question.`);
41
+ return;
42
+ }
43
+ let options = (p.options ?? []).map((o) => String(o).trim()).filter(Boolean);
44
+ let recommended = Number.isInteger(p.recommended) && p.recommended >= 1 && p.recommended <= options.length ? p.recommended : 1;
45
+ // Settled by words already on record: the materials' (brief) or the researcher's own (researcher).
46
+ const brief = (p.by === "brief" || p.by === "researcher") && !!p.quote?.trim();
47
+ const analyst = p.by === "analyst" && !!p.reason?.trim();
48
+ const impact0 = p.impact === "key" || p.impact === "intent" || p.impact === "convention" ? p.impact : (brief || analyst ? "convention" : "intent");
49
+ const promoted = analyst && (impact0 !== "convention" || INTENT_PATTERN.test(question) || promote.has(i));
50
+ const open = !brief && !(analyst && !promoted);
51
+ const impact = open ? (impact0 === "key" ? "key" : "intent") : "convention";
52
+ if (open && options.length < 2) {
53
+ problems.push(promoted
54
+ ? `${at} (${question}): this depends on the researcher's intent, so the analyst cannot settle it; give 2-${MAX_OPTIONS} options with your choice as the recommendation.`
55
+ : `${at} (${question}): an open point needs 2-${MAX_OPTIONS} options, or by brief / by researcher with the quote, or by analyst with the reason for a convention.`);
56
+ }
57
+ if (open && options.length > MAX_OPTIONS) {
58
+ if (promoted) {
59
+ // Keep the recommended option and the first others.
60
+ const keep = [options[recommended - 1], ...options.filter((_o, k) => k !== recommended - 1)].slice(0, MAX_OPTIONS);
61
+ options = keep;
62
+ recommended = 1;
63
+ }
64
+ else
65
+ problems.push(`${at} (${question}): at most ${MAX_OPTIONS} options; keep the ones used in the field (the researcher can still write their own).`);
66
+ }
67
+ if (impact === "key" && !p.why?.trim())
68
+ problems.push(`${at} (${question}): a key point needs why: one line on what changes in the result depending on the choice.`);
69
+ staged.push({ ...p, question, options, recommended, open, impact, ...(p.why?.trim() ? { why: p.why.trim() } : {}), ...(promoted ? { promoted: true } : {}) });
70
+ });
71
+ const ordered = staged.map((x, i) => ({ x, i })).sort((a, b) => TIER[a.x.impact] - TIER[b.x.impact] || a.i - b.i).map(({ x }) => x);
72
+ const out = ordered.map((x, k) => ({ ...x, n: k + 1, id: pointId(planId, k + 1) }));
73
+ return { points: out, problems, promoted: out.filter((x) => x.promoted).map((x) => `D${x.n}`) };
74
+ }
75
+ /** The first sentence or line of a long text, at most `max` characters (the goal row, not the whole brief). */
76
+ export function oneLine(text, max = 100) {
77
+ const first = text.trim().split(/\r?\n|(?<=[。!?])|(?<=[.!?])\s/)[0].replace(/^#+\s*/, "").trim();
78
+ return first.length > max ? `${first.slice(0, max - 1)}…` : first;
79
+ }
80
+ /**
81
+ * The message for the researcher, in four blocks by what they need to do (design 11-29, A3–A4):
82
+ * 1. key decisions (at most MAX_KEY, in full, each with what changes);
83
+ * 2. the other open decisions, one line each with the recommendation;
84
+ * 3. analyses the analyst adds beyond the request, with the reason;
85
+ * 4. what the materials or conventions settle, one line each, open to change.
86
+ */
87
+ export function renderPlanMessage(plan, points, additions = []) {
88
+ const open = points.filter((p) => p.open);
89
+ const key = open.filter((p) => p.impact === "key").slice(0, MAX_KEY);
90
+ const rest = open.filter((p) => !key.includes(p));
91
+ const settled = points.filter((p) => !p.open);
92
+ const lines = [`## 分析方案(${open.length} 项待你定${key.length ? `,其中 ${key.length} 项关键` : ""};回复一次即可)`, ""];
93
+ const row = (label, value) => { if (value?.trim())
94
+ lines.push(`- ${label}:${value.trim()}`); };
95
+ row("目标", plan.goal ? oneLine(plan.goal) : undefined);
96
+ row("主要结果", plan.primaryOutcome);
97
+ row("主分析", plan.primaryAnalysis);
98
+ if (plan.proposedMethods?.length)
99
+ row("其他分析", plan.proposedMethods.join(";"));
100
+ // "待澄清后声明" is the new plan's placeholder, not an analysis.
101
+ const exploratory = (plan.exploratoryAnalyses ?? []).filter((x) => x.trim() && x.trim() !== "待澄清后声明");
102
+ if (exploratory.length)
103
+ row("探索性分析", exploratory.join(";"));
104
+ row("排除标准", plan.exclusionCriteria);
105
+ row("缺失值", plan.missingDataPlan);
106
+ row("多重比较", plan.multiplicityPlan);
107
+ const tag = (p) => (p.rq ? `(${p.rq})` : "");
108
+ let block = 0;
109
+ const heading = (text) => { block += 1; lines.push("", `### ${"一二三四"[block - 1]}、${text}`); };
110
+ if (key.length) {
111
+ heading("关键决定(会改变结论,请逐项看)");
112
+ for (const p of key) {
113
+ lines.push("", `**D${p.n}**${tag(p)} ${p.question}`);
114
+ if (p.why)
115
+ lines.push(`选哪个会改变:${p.why}`);
116
+ p.options.forEach((o, i) => lines.push(`${i + 1}) ${o}${i + 1 === p.recommended ? "(推荐)" : ""}`));
117
+ }
118
+ }
119
+ if (rest.length) {
120
+ heading(key.length ? "其余待你定的(不写就按推荐)" : "待你定的(不写就按推荐)");
121
+ for (const p of rest) {
122
+ const others = p.options.map((o, i) => ({ o, i })).filter(({ i }) => i + 1 !== p.recommended).map(({ o, i }) => `${i + 1}) ${o}`);
123
+ lines.push(`- **D${p.n}**${tag(p)} ${p.question}:推荐 ${p.recommended}) ${p.options[p.recommended - 1]}${others.length ? `;也可以 ${others.join(";")}` : ""}`);
124
+ }
125
+ }
126
+ if (additions.length) {
127
+ heading("我打算补的分析(不需要的说一声)");
128
+ for (const a of additions)
129
+ lines.push(`- ${a.analysis}:${a.reason}`);
130
+ }
131
+ if (settled.length) {
132
+ heading("按你说过的、材料或惯例定下的(不同意可以改)");
133
+ for (const p of settled) {
134
+ const basis = p.by === "researcher" ? `你说过:「${p.quote.trim()}」` : p.by === "brief" ? `材料:「${p.quote.trim()}」` : `惯例:${p.reason.trim()}`;
135
+ const choice = p.options?.[p.recommended - 1];
136
+ lines.push(`- **D${p.n}**${tag(p)} ${p.question}${choice ? `:${choice}` : ""}(${basis})`);
137
+ }
138
+ }
139
+ lines.push("", "### 怎么回复", "一条消息定下全部:同意推荐就写「全部按推荐」;要改的写编号和选项,比如「D2 选 2」「D5 改成……」。", "如果你原本的做法不一样,直接写你的做法。也请指出方案漏掉的分析(要补的检验、分组、要报告的量)。", "回复里写「批准」就按定下的方案开始分析。");
140
+ return lines.join("\n");
141
+ }
142
+ /**
143
+ * Turns the researcher's one reply (already read by the model into per-point answers) into
144
+ * decisions. Points the reply does not name take the recommendation when `rest` is
145
+ * "recommended"; otherwise they stay open. Returns the settlements and the points still open.
146
+ */
147
+ export function settleFromReply(open, answers, rest) {
148
+ const settle = [];
149
+ const problems = [];
150
+ const byLabel = new Map(open.map((d) => [pointLabel(d.id).toUpperCase(), d]));
151
+ const named = new Set();
152
+ for (const a of answers) {
153
+ const key = pointLabel(String(a.d ?? "").trim()).toUpperCase().replace(/^(\d+)$/, "D$1");
154
+ const d = byLabel.get(key);
155
+ if (!d) {
156
+ problems.push(`${a.d}: not an open point.`);
157
+ continue;
158
+ }
159
+ const text = a.text?.trim();
160
+ let choice;
161
+ if (text)
162
+ choice = text;
163
+ else if (Number.isInteger(a.option) && a.option >= 1 && a.option <= d.options.length)
164
+ choice = d.options[a.option - 1].label;
165
+ if (!choice) {
166
+ problems.push(`${key}: give option (1-${d.options.length}) or text.`);
167
+ continue;
168
+ }
169
+ named.add(d.id);
170
+ settle.push({ id: d.id, choice, named: true });
171
+ }
172
+ const left = [];
173
+ for (const d of open) {
174
+ if (named.has(d.id))
175
+ continue;
176
+ if (rest === "recommended") {
177
+ const choice = d.recommendation ?? d.options[0]?.label;
178
+ if (choice) {
179
+ settle.push({ id: d.id, choice, named: false });
180
+ continue;
181
+ }
182
+ }
183
+ left.push(d.id);
184
+ }
185
+ return { settle, left, problems };
186
+ }
187
+ //# sourceMappingURL=plan-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-message.js","sourceRoot":"","sources":["../../../src/research/plan-message.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiCH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,CAAS,EAAU,EAAE,CAAC,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC;AAChF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAElF,iGAAiG;AACjG,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,8FAA8F;AAC9F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,+YAA+Y,CAAC;AAE9a,MAAM,IAAI,GAAgC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAAmB,EAAE,UAA+B,IAAI,GAA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AAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAAE,SAAS;QAC9B,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;YACvD,IAAI,MAAM,EAAE,CAAC;gBAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;gBAAC,SAAS;YAAC,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { Decision } from "./decisions.js";
2
+ import type { IntentState } from "./intent.js";
3
+ export declare const PRACTICE_PATH: "analysis/practice_comparison.md";
4
+ export interface PracticeCheck {
5
+ /** A decision id or its plan label (D3), or an intent question (I1). */
6
+ d: string;
7
+ status: "done" | "changed" | "not-done";
8
+ /** done: the file(s) that show it (script, table), comma-separated, relative to the project. */
9
+ where?: string;
10
+ /** done: words copied from that file that show it (a code line, a column name, a row), found verbatim. */
11
+ evidence?: string;
12
+ /** changed: what was done instead. */
13
+ to?: string;
14
+ /** changed / not-done: why. */
15
+ note?: string;
16
+ }
17
+ export interface AskedRow {
18
+ key: string;
19
+ label: string;
20
+ asked: string;
21
+ basis: string;
22
+ decisionId?: string;
23
+ }
24
+ /** The rows the researcher asked for: their decisions, the brief's, and the research questions of the intent. */
25
+ export declare function askedRows(decisions: Decision[], intent?: IntentState): AskedRow[];
26
+ /** The row a check names: its full id or label, or the first word of its label (I1 for "I1 RQ1"), any case. */
27
+ export declare function rowFor(rows: AskedRow[], d: string): AskedRow | undefined;
28
+ /** Paths a check names: comma-separated, each its first word, without a #anchor or :line suffix. */
29
+ export declare function pathsOf(where: string | undefined): string[];
30
+ /** Checks every asked row has a check, and every check is complete. Returns the problems (empty when fine). */
31
+ export declare function checkProblems(cwd: string, rows: AskedRow[], checks: PracticeCheck[]): string[];
32
+ /** The comparison as markdown, to be put at the top of the report unchanged. */
33
+ export declare function renderPractice(decisions: Decision[], rows: AskedRow[], checks: PracticeCheck[]): string;