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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ResearchParadigm } from "../../core/contracts.js";
|
|
2
|
+
/** User-facing usage for `/init`. Prefix `Usage:` so telemetry treats it as expected. */
|
|
3
|
+
export declare const INIT_USAGE = "Usage: /init [--paradigm survey-observational] [\u7814\u7A76\u76EE\u6807]";
|
|
4
|
+
export type ParsedInitArgs = {
|
|
5
|
+
ok: true;
|
|
6
|
+
goal?: string;
|
|
7
|
+
paradigm?: ResearchParadigm;
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Parse `/init` args without throwing. Bare `/init` still scaffolds; flag-shaped
|
|
14
|
+
* input that is missing a goal or uses an unknown option returns a usage hint.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseInitArgs(args: string): ParsedInitArgs;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const PARADIGMS = new Set([
|
|
2
|
+
"survey-observational",
|
|
3
|
+
"qualitative-thematic",
|
|
4
|
+
"experimental",
|
|
5
|
+
"quasi-experimental",
|
|
6
|
+
"longitudinal-panel",
|
|
7
|
+
"meta-analysis",
|
|
8
|
+
"ethnographic",
|
|
9
|
+
"historical-documentary",
|
|
10
|
+
"policy-legal",
|
|
11
|
+
"mixed-methods",
|
|
12
|
+
]);
|
|
13
|
+
/** User-facing usage for `/init`. Prefix `Usage:` so telemetry treats it as expected. */
|
|
14
|
+
export const INIT_USAGE = "Usage: /init [--paradigm survey-observational] [研究目标]";
|
|
15
|
+
/**
|
|
16
|
+
* Parse `/init` args without throwing. Bare `/init` still scaffolds; flag-shaped
|
|
17
|
+
* input that is missing a goal or uses an unknown option returns a usage hint.
|
|
18
|
+
*/
|
|
19
|
+
export function parseInitArgs(args) {
|
|
20
|
+
const trimmed = args.trim();
|
|
21
|
+
if (!trimmed)
|
|
22
|
+
return { ok: true };
|
|
23
|
+
if (trimmed.startsWith("-")) {
|
|
24
|
+
const match = trimmed.match(/^--paradigm(?:=|\s+)(\S+)(?:\s+([\s\S]*))?$/i);
|
|
25
|
+
const paradigm = match?.[1];
|
|
26
|
+
const goal = match?.[2]?.trim();
|
|
27
|
+
if (!match || !paradigm) {
|
|
28
|
+
return { ok: false, message: INIT_USAGE };
|
|
29
|
+
}
|
|
30
|
+
if (!PARADIGMS.has(paradigm)) {
|
|
31
|
+
return { ok: false, message: `Unsupported paradigm: ${paradigm}\n${INIT_USAGE}` };
|
|
32
|
+
}
|
|
33
|
+
if (!goal) {
|
|
34
|
+
return { ok: false, message: INIT_USAGE };
|
|
35
|
+
}
|
|
36
|
+
return { ok: true, paradigm, goal };
|
|
37
|
+
}
|
|
38
|
+
return { ok: true, paradigm: "survey-observational", goal: trimmed };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=init-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-args.js","sourceRoot":"","sources":["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EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,sBAAsB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DECISION_SOURCES: readonly ["brief", "data", "convention", "intent"];
|
|
1
|
+
export declare const DECISION_SOURCES: readonly ["brief", "data", "convention", "equivalent", "intent"];
|
|
2
2
|
export type DecisionSource = (typeof DECISION_SOURCES)[number];
|
|
3
3
|
export declare const DECISION_POINTS_HEADING = "## Decision points";
|
|
4
4
|
export declare const VERDICT_RULES_HEADING = "## Verdict rules";
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { readFile } from "node:fs/promises";
|
|
12
12
|
import { resolve } from "node:path";
|
|
13
|
-
export const DECISION_SOURCES = ["brief", "data", "convention", "intent"];
|
|
13
|
+
export const DECISION_SOURCES = ["brief", "data", "convention", "equivalent", "intent"];
|
|
14
14
|
export const DECISION_POINTS_HEADING = "## Decision points";
|
|
15
15
|
export const VERDICT_RULES_HEADING = "## Verdict rules";
|
|
16
16
|
const PLAN_PATH = "analysis/plans/plan.md";
|
|
@@ -38,6 +38,10 @@ export function tableRowsUnder(markdown, heading) {
|
|
|
38
38
|
.filter((row) => row.some((cell) => cell !== ""))
|
|
39
39
|
.map((row) => Object.fromEntries(header.map((name, i) => [name, row[i] ?? ""])));
|
|
40
40
|
}
|
|
41
|
+
const STAGE4_DECISION = /\b(alpha|tails?|tailed|multiplicity|multiple[- ]comparisons?|equivalence|support rule|α|单双尾|多重比较|支持规则)\b/i;
|
|
42
|
+
function isStage4Decision(row) {
|
|
43
|
+
return STAGE4_DECISION.test(`${row["id"] ?? ""} ${row["decision"] ?? ""}`);
|
|
44
|
+
}
|
|
41
45
|
function sourceOf(value) {
|
|
42
46
|
const lowered = value.toLowerCase();
|
|
43
47
|
return DECISION_SOURCES.find((source) => lowered.startsWith(source));
|
|
@@ -62,6 +66,9 @@ export function checkDecisionPoints(planMarkdown) {
|
|
|
62
66
|
if (source === "intent" && !(row["alternative (sensitivity)"] ?? row["alternative"] ?? "").trim()) {
|
|
63
67
|
findings.push(`Decision ${id} depends on researcher intent: run the main alternative as a labelled sensitivity analysis, or note who settled it.`);
|
|
64
68
|
}
|
|
69
|
+
if (source === "intent" && isStage4Decision(row)) {
|
|
70
|
+
findings.push(`Decision ${id} is an inference or support rule (alpha, tails, multiplicity, equivalence, or what counts as support). Declare it; do not ask.`);
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
const verdicts = tableRowsUnder(planMarkdown, VERDICT_RULES_HEADING);
|
|
67
74
|
if (verdicts.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-points.js","sourceRoot":"","sources":["../../../src/analysis/decision-points.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"decision-points.js","sourceRoot":"","sources":["../../../src/analysis/decision-points.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAU,CAAC;AAGjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACxD,MAAM,SAAS,G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AAC;AAED,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAAY;IACrD,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAChG,OAAO,CAAC,eAAe,SAAS,mBAAmB,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ChoiceLike {
|
|
2
|
+
prompt: string;
|
|
3
|
+
originalResponse: string;
|
|
4
|
+
selectedIds: string[];
|
|
5
|
+
selectedLabels: string[];
|
|
6
|
+
context?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Later records win. A token is applied only when exactly one candidate constant lists it. */
|
|
9
|
+
export declare function updatesFromChoices(source: string, records: readonly ChoiceLike[]): Map<string, string>;
|
|
10
|
+
export declare function applyConstantValues(source: string, updates: ReadonlyMap<string, string>): string;
|
|
11
|
+
export declare function readChoiceRecords(root: string): Promise<ChoiceLike[]>;
|
|
12
|
+
export declare function rewriteScriptFromChoices(root: string, scriptRelative: string, source: string): Promise<{
|
|
13
|
+
source: string;
|
|
14
|
+
changes: string[];
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write the researcher's confirmed option into each @intent constant, then
|
|
3
|
+
* re-render the plan so the script that runs is the one they approved.
|
|
4
|
+
*/
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { atomicWriteFile } from "../../project/jsonl.js";
|
|
8
|
+
import { assertSafeProjectPath } from "../../project/paths.js";
|
|
9
|
+
import { optionIds, parseConstants } from "./constants.js";
|
|
10
|
+
import { renderPriorPlan } from "./render.js";
|
|
11
|
+
const PRIOR_PLAN_REL = "analysis/plans/plan.md";
|
|
12
|
+
const ASSIGN = /^([A-Z][A-Z0-9_]*)(\s*(?:=|<-)\s*)(.*)$/;
|
|
13
|
+
function literal(value) {
|
|
14
|
+
return /^-?\d+(?:\.\d+)?$/.test(value) ? value : JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
/** Later records win. A token is applied only when exactly one candidate constant lists it. */
|
|
17
|
+
export function updatesFromChoices(source, records) {
|
|
18
|
+
const constants = parseConstants(source).filter((constant) => constant.label === "intent");
|
|
19
|
+
const updates = new Map();
|
|
20
|
+
for (const record of records) {
|
|
21
|
+
const named = constants.filter((constant) => new RegExp(`\\b${constant.name}\\b`).test(`${record.prompt}\n${record.context ?? ""}`));
|
|
22
|
+
const pool = named.length > 0 ? named : constants;
|
|
23
|
+
const tokens = [...record.selectedIds, ...record.selectedLabels, record.originalResponse.trim()];
|
|
24
|
+
for (const token of tokens) {
|
|
25
|
+
const value = token.trim();
|
|
26
|
+
if (!value)
|
|
27
|
+
continue;
|
|
28
|
+
const hits = pool.filter((constant) => optionIds(constant).includes(value));
|
|
29
|
+
if (hits.length === 1 && hits[0])
|
|
30
|
+
updates.set(hits[0].name, value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return updates;
|
|
34
|
+
}
|
|
35
|
+
export function applyConstantValues(source, updates) {
|
|
36
|
+
const newline = source.endsWith("\n") ? "\n" : "";
|
|
37
|
+
const lines = source.replace(/\n$/, "").split(/\r?\n/).map((line) => {
|
|
38
|
+
if (line.startsWith(" ") || line.startsWith("\t"))
|
|
39
|
+
return line;
|
|
40
|
+
const match = ASSIGN.exec(line);
|
|
41
|
+
if (!match)
|
|
42
|
+
return line;
|
|
43
|
+
const name = match[1] ?? "";
|
|
44
|
+
const next = updates.get(name);
|
|
45
|
+
if (next === undefined)
|
|
46
|
+
return line;
|
|
47
|
+
const rhs = match[3] ?? "";
|
|
48
|
+
const hash = rhs.indexOf("#");
|
|
49
|
+
const comment = hash < 0 ? "" : rhs.slice(hash).trim();
|
|
50
|
+
return `${name}${match[2] ?? " = "}${literal(next)}${comment ? ` ${comment}` : ""}`;
|
|
51
|
+
});
|
|
52
|
+
return `${lines.join("\n")}${newline || "\n"}`;
|
|
53
|
+
}
|
|
54
|
+
export async function readChoiceRecords(root) {
|
|
55
|
+
let text = "";
|
|
56
|
+
try {
|
|
57
|
+
text = await readFile(join(root, ".psyclaw/choices.jsonl"), "utf8");
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const records = [];
|
|
63
|
+
for (const line of text.split(/\r?\n/)) {
|
|
64
|
+
if (!line.trim())
|
|
65
|
+
continue;
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(line);
|
|
68
|
+
if (typeof parsed.prompt !== "string" || typeof parsed.originalResponse !== "string")
|
|
69
|
+
continue;
|
|
70
|
+
records.push({
|
|
71
|
+
prompt: parsed.prompt,
|
|
72
|
+
originalResponse: parsed.originalResponse,
|
|
73
|
+
selectedIds: Array.isArray(parsed.selectedIds) ? parsed.selectedIds.filter((item) => typeof item === "string") : [],
|
|
74
|
+
selectedLabels: Array.isArray(parsed.selectedLabels) ? parsed.selectedLabels.filter((item) => typeof item === "string") : [],
|
|
75
|
+
...(typeof parsed.context === "string" ? { context: parsed.context } : {}),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch { /* skip a broken line */ }
|
|
79
|
+
}
|
|
80
|
+
return records;
|
|
81
|
+
}
|
|
82
|
+
export async function rewriteScriptFromChoices(root, scriptRelative, source) {
|
|
83
|
+
const updates = updatesFromChoices(source, await readChoiceRecords(root));
|
|
84
|
+
const constants = new Map(parseConstants(source).map((constant) => [constant.name, constant]));
|
|
85
|
+
const changes = [];
|
|
86
|
+
for (const [name, value] of updates) {
|
|
87
|
+
if (constants.get(name)?.value === value)
|
|
88
|
+
continue;
|
|
89
|
+
changes.push(`${name} = ${value}`);
|
|
90
|
+
}
|
|
91
|
+
if (changes.length === 0)
|
|
92
|
+
return { source, changes };
|
|
93
|
+
const next = applyConstantValues(source, updates);
|
|
94
|
+
await atomicWriteFile(await assertSafeProjectPath(root, scriptRelative), next);
|
|
95
|
+
await atomicWriteFile(await assertSafeProjectPath(root, PRIOR_PLAN_REL), renderPriorPlan(next).markdown);
|
|
96
|
+
return { source: next, changes };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../src/analysis/prior/apply.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAsB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,cAAc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,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,eAAe,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/E,MAAM,eAAe,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IACzG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks for a prior-mode script. An empty list means the script can be rendered.
|
|
3
|
+
* Statistical procedures stay in the script; this module only reads labels.
|
|
4
|
+
*/
|
|
5
|
+
import { type PriorConstant } from "./constants.js";
|
|
6
|
+
export interface ScriptFunction {
|
|
7
|
+
name: string;
|
|
8
|
+
body: string;
|
|
9
|
+
descriptive: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function scriptFunctions(source: string): ScriptFunction[];
|
|
12
|
+
export declare function checkRecall(text: string): string[];
|
|
13
|
+
/** Approach ids from `- id: ...` lines, excluding the four recall slots. */
|
|
14
|
+
export declare function recalledApproachIds(text: string): string[];
|
|
15
|
+
interface Dependency {
|
|
16
|
+
parent: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function dependencyOf(source: string, constant: PriorConstant, constants: readonly PriorConstant[]): Dependency | undefined;
|
|
20
|
+
export declare function checkPlanScript(source: string, recallText: string): string[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks for a prior-mode script. An empty list means the script can be rendered.
|
|
3
|
+
* Statistical procedures stay in the script; this module only reads labels.
|
|
4
|
+
*/
|
|
5
|
+
import { isStage4, optionIds, parseConstants } from "./constants.js";
|
|
6
|
+
const PY_DEF = /^def\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(/;
|
|
7
|
+
const R_DEF = /^([A-Za-z.][A-Za-z0-9._]*)\s*<-\s*function\b/;
|
|
8
|
+
const DESCRIPTIVE_NAME = /describ|explor|eda|profile|missing|codebook|covariate/i;
|
|
9
|
+
const HYPOTHESIS_MARK = /\bH\d+\b|hypoth|confirmatory|假设/;
|
|
10
|
+
const CONDITION = /\b(?:if|when|若)\s+([A-Z][A-Z0-9_]*)\s*(?:==|=|is|为)\s*["']?([\w.-]+)/i;
|
|
11
|
+
const IF_LINE = /^(\s*)if\b\s*\(?\s*([A-Z][A-Z0-9_]*)\s*==\s*["']?([\w.-]+)/;
|
|
12
|
+
const ITEM = /^\s*[-*]\s*`?([A-Za-z0-9_][A-Za-z0-9_.-]*)`?\s*:/gm;
|
|
13
|
+
const SLOT_IDS = new Set([
|
|
14
|
+
"construct",
|
|
15
|
+
"internal_validity",
|
|
16
|
+
"internal",
|
|
17
|
+
"validity",
|
|
18
|
+
"statistical_conclusion",
|
|
19
|
+
"conclusion",
|
|
20
|
+
"dependence",
|
|
21
|
+
"构念",
|
|
22
|
+
"内部效度",
|
|
23
|
+
"统计结论",
|
|
24
|
+
"依赖",
|
|
25
|
+
]);
|
|
26
|
+
const STOP = new Set([
|
|
27
|
+
"the", "and", "for", "with", "use", "used", "using", "usually", "score", "scores", "scored", "scoring",
|
|
28
|
+
"analysis", "analyse", "analysed", "test", "tests", "model", "design", "problem", "problems", "data",
|
|
29
|
+
"item", "items", "study", "studies",
|
|
30
|
+
]);
|
|
31
|
+
const RECALL_SLOTS = [
|
|
32
|
+
{ label: "construct", re: /construct|构念/i },
|
|
33
|
+
{ label: "internal validity", re: /internal[_\s-]*validity|内部效度/i },
|
|
34
|
+
{ label: "statistical conclusion", re: /statistical[_\s-]*conclusion|统计结论/i },
|
|
35
|
+
{ label: "dependence", re: /dependence|依赖/i },
|
|
36
|
+
];
|
|
37
|
+
function functionEnd(lines, start) {
|
|
38
|
+
for (let index = start + 1; index < lines.length; index += 1) {
|
|
39
|
+
const line = lines[index] ?? "";
|
|
40
|
+
if (line.trim() === "")
|
|
41
|
+
continue;
|
|
42
|
+
if (line.startsWith(" ") || line.startsWith("\t"))
|
|
43
|
+
continue;
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
return lines.length;
|
|
47
|
+
}
|
|
48
|
+
export function scriptFunctions(source) {
|
|
49
|
+
const lines = source.split(/\r?\n/);
|
|
50
|
+
const starts = [];
|
|
51
|
+
lines.forEach((line, index) => {
|
|
52
|
+
if (line.startsWith(" ") || line.startsWith("\t"))
|
|
53
|
+
return;
|
|
54
|
+
const name = PY_DEF.exec(line)?.[1] ?? R_DEF.exec(line)?.[1];
|
|
55
|
+
if (name)
|
|
56
|
+
starts.push({ name, index });
|
|
57
|
+
});
|
|
58
|
+
return starts.map((start) => {
|
|
59
|
+
const body = lines.slice(start.index, functionEnd(lines, start.index)).join("\n");
|
|
60
|
+
const descriptive = DESCRIPTIVE_NAME.test(start.name) && !HYPOTHESIS_MARK.test(body);
|
|
61
|
+
return { name: start.name, body, descriptive };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function checkRecall(text) {
|
|
65
|
+
const body = text.trim();
|
|
66
|
+
if (!body)
|
|
67
|
+
return ["Recall is empty. For each hypothesis, write construct, internal validity, statistical conclusion, and dependence."];
|
|
68
|
+
const problems = [];
|
|
69
|
+
for (const block of hypothesisBlocks(body)) {
|
|
70
|
+
const title = block.split(/\r?\n/).find((line) => line.trim())?.trim() ?? "recall";
|
|
71
|
+
for (const slot of RECALL_SLOTS) {
|
|
72
|
+
if (!slot.re.test(block))
|
|
73
|
+
problems.push(`${title}: missing ${slot.label}.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return problems;
|
|
77
|
+
}
|
|
78
|
+
function hypothesisBlocks(text) {
|
|
79
|
+
const lines = text.split(/\r?\n/);
|
|
80
|
+
const indexes = lines.flatMap((line, index) => (/^#{1,3}\s+\S/.test(line) || /^H\d+\b/.test(line) ? [index] : []));
|
|
81
|
+
if (indexes.length === 0)
|
|
82
|
+
return [text];
|
|
83
|
+
return indexes.map((start, index) => lines.slice(start, indexes[index + 1] ?? lines.length).join("\n"));
|
|
84
|
+
}
|
|
85
|
+
/** Approach ids from `- id: ...` lines, excluding the four recall slots. */
|
|
86
|
+
export function recalledApproachIds(text) {
|
|
87
|
+
return [...text.matchAll(ITEM)]
|
|
88
|
+
.map((match) => match[1] ?? "")
|
|
89
|
+
.filter((id) => id && !SLOT_IDS.has(id.toLowerCase()));
|
|
90
|
+
}
|
|
91
|
+
function words(text) {
|
|
92
|
+
const out = new Set();
|
|
93
|
+
for (const raw of text.toLowerCase().split(/[^a-z0-9]+/)) {
|
|
94
|
+
if (raw.length < 3 || STOP.has(raw))
|
|
95
|
+
continue;
|
|
96
|
+
out.add(raw.length > 4 && raw.endsWith("s") && !raw.endsWith("ss") ? raw.slice(0, -1) : raw);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function overlap(left, right) {
|
|
101
|
+
if (left.size === 0 || right.size === 0)
|
|
102
|
+
return 0;
|
|
103
|
+
let shared = 0;
|
|
104
|
+
for (const word of left)
|
|
105
|
+
if (right.has(word))
|
|
106
|
+
shared += 1;
|
|
107
|
+
const union = left.size + right.size - shared;
|
|
108
|
+
return union === 0 ? 0 : shared / union;
|
|
109
|
+
}
|
|
110
|
+
function covered(recallId, constants) {
|
|
111
|
+
const rid = words(recallId);
|
|
112
|
+
for (const constant of constants) {
|
|
113
|
+
const options = optionIds(constant);
|
|
114
|
+
if (options.some((option) => option.toLowerCase().includes(recallId.toLowerCase())))
|
|
115
|
+
return true;
|
|
116
|
+
if (options.some((option) => overlap(rid, words(option)) >= 0.5))
|
|
117
|
+
return true;
|
|
118
|
+
const bag = words([constant.name, ...options].join(" "));
|
|
119
|
+
if (rid.size > 0) {
|
|
120
|
+
let shared = 0;
|
|
121
|
+
for (const word of rid)
|
|
122
|
+
if (bag.has(word))
|
|
123
|
+
shared += 1;
|
|
124
|
+
if (shared >= rid.size / 2)
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function dependenciesFromCode(source, names) {
|
|
131
|
+
const loads = new Map();
|
|
132
|
+
const stack = [];
|
|
133
|
+
for (const line of source.split(/\r?\n/)) {
|
|
134
|
+
const indent = line.match(/^\s*/)?.[0].length ?? 0;
|
|
135
|
+
while (stack.length > 0 && indent <= (stack.at(-1)?.indent ?? 0))
|
|
136
|
+
stack.pop();
|
|
137
|
+
const frame = stack.at(-1);
|
|
138
|
+
const assignment = /^(\s*)([A-Z][A-Z0-9_]*)\s*(?:=|<-)/.exec(line);
|
|
139
|
+
if (!(assignment && names.has(assignment[2] ?? ""))) {
|
|
140
|
+
for (const name of names) {
|
|
141
|
+
if (new RegExp(`\\b${name}\\b`).test(line)) {
|
|
142
|
+
const list = loads.get(name) ?? [];
|
|
143
|
+
list.push(frame ? { parent: frame.parent, value: frame.value } : null);
|
|
144
|
+
loads.set(name, list);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const conditional = IF_LINE.exec(line);
|
|
149
|
+
if (conditional && names.has(conditional[2] ?? "")) {
|
|
150
|
+
stack.push({ indent, parent: conditional[2] ?? "", value: conditional[3] ?? "" });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const requires = new Map();
|
|
154
|
+
for (const [name, sites] of loads) {
|
|
155
|
+
if (sites.length === 0 || sites.some((site) => site === null))
|
|
156
|
+
continue;
|
|
157
|
+
const first = sites[0];
|
|
158
|
+
if (!first)
|
|
159
|
+
continue;
|
|
160
|
+
if (sites.every((site) => site?.parent === first.parent && site?.value === first.value)) {
|
|
161
|
+
requires.set(name, first);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return requires;
|
|
165
|
+
}
|
|
166
|
+
export function dependencyOf(source, constant, constants) {
|
|
167
|
+
const fromCode = dependenciesFromCode(source, new Set(constants.map((item) => item.name))).get(constant.name);
|
|
168
|
+
if (fromCode)
|
|
169
|
+
return fromCode;
|
|
170
|
+
const match = CONDITION.exec(constant.reason);
|
|
171
|
+
if (!match)
|
|
172
|
+
return undefined;
|
|
173
|
+
const parent = constants.find((item) => item.name === match[1]);
|
|
174
|
+
const value = match[2] ?? "";
|
|
175
|
+
if (!parent || !optionIds(parent).includes(value))
|
|
176
|
+
return { parent: match[1] ?? "", value };
|
|
177
|
+
return { parent: parent.name, value };
|
|
178
|
+
}
|
|
179
|
+
export function checkPlanScript(source, recallText) {
|
|
180
|
+
const constants = parseConstants(source);
|
|
181
|
+
const problems = [];
|
|
182
|
+
if (!constants.some((constant) => constant.label)) {
|
|
183
|
+
problems.push("No labeled constant. Each analysis choice needs @intent, @declare, or @pseudo on a top-level constant.");
|
|
184
|
+
}
|
|
185
|
+
for (const constant of constants) {
|
|
186
|
+
if (!constant.label) {
|
|
187
|
+
problems.push(`${constant.name} (line ${constant.line}) has no label. Use @declare or @pseudo if it is not a choice.`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (constant.label === "intent" && isStage4(constant.name)) {
|
|
191
|
+
problems.push(`${constant.name} is inference or a support rule (stage 4: alpha, tails, multiplicity, equivalence, what counts as support). Label it @declare and do not ask.`);
|
|
192
|
+
}
|
|
193
|
+
if (constant.label === "intent") {
|
|
194
|
+
const others = constant.alternatives.filter((item) => item !== constant.value);
|
|
195
|
+
if (others.length < 1)
|
|
196
|
+
problems.push(`${constant.name} is @intent but lists no other value after |.`);
|
|
197
|
+
if (!constant.reason)
|
|
198
|
+
problems.push(`${constant.name} is @intent but has no reason after the dash.`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const functions = scriptFunctions(source);
|
|
202
|
+
for (const constant of constants) {
|
|
203
|
+
if (constant.label !== "intent" || isStage4(constant.name))
|
|
204
|
+
continue;
|
|
205
|
+
const users = functions.filter((fn) => new RegExp(`\\b${constant.name}\\b`).test(fn.body));
|
|
206
|
+
const hypothesisUse = users.some((fn) => !fn.descriptive);
|
|
207
|
+
if (!hypothesisUse) {
|
|
208
|
+
problems.push(`${constant.name} is @intent but is not used by a hypothesis test. If it only feeds a description, an exploration, or a covariate screen, label it @declare.`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const constant of constants) {
|
|
212
|
+
if (!constant.label)
|
|
213
|
+
continue;
|
|
214
|
+
const match = CONDITION.exec(constant.reason);
|
|
215
|
+
if (!match)
|
|
216
|
+
continue;
|
|
217
|
+
const parent = constants.find((item) => item.name === match[1]);
|
|
218
|
+
const value = match[2] ?? "";
|
|
219
|
+
if (!parent)
|
|
220
|
+
problems.push(`${constant.name} depends on ${match[1]}, which is not a labeled constant.`);
|
|
221
|
+
else if (!optionIds(parent).includes(value))
|
|
222
|
+
problems.push(`${constant.name} depends on ${parent.name} == ${value}, which is not one of that constant's values.`);
|
|
223
|
+
}
|
|
224
|
+
const missing = recalledApproachIds(recallText).filter((id) => !covered(id, constants));
|
|
225
|
+
if (missing.length > 0) {
|
|
226
|
+
problems.push(`These recalled approaches are not options of any constant: ${missing.join(", ")}. Add them (they may be @declare or @pseudo). Do not drop them.`);
|
|
227
|
+
}
|
|
228
|
+
if (!constants.some((constant) => constant.label === "declare" && isStage4(constant.name))) {
|
|
229
|
+
problems.push("Stage 4 is missing. Declare alpha, tails, multiplicity, or the support rule as an @declare constant.");
|
|
230
|
+
}
|
|
231
|
+
return problems;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../../../../src/analysis/prior/checks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAs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AC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IACxF,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,8DAA8D,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;IACnK,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAC3F,QAAQ,CAAC,IAAI,CAAC,sGAAsG,CAAC,CAAC;IACxH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prior mode reads the plan from labeled constants at the top of an analysis script.
|
|
3
|
+
*
|
|
4
|
+
* NAME = value # @intent value | other — why the researcher must choose
|
|
5
|
+
* NAME = value # @declare — why this needs no question
|
|
6
|
+
* NAME = value # @pseudo — why the options cannot differ for any data
|
|
7
|
+
*
|
|
8
|
+
* One assignment per line, at column 0. Python `=` and R `<-` both count.
|
|
9
|
+
* A comment directly above the constant, short and not itself a label, is the
|
|
10
|
+
* hypothesis group it affects.
|
|
11
|
+
*/
|
|
12
|
+
export type PriorLabel = "intent" | "declare" | "pseudo";
|
|
13
|
+
export interface PriorConstant {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
line: number;
|
|
17
|
+
group: string;
|
|
18
|
+
label: PriorLabel | null;
|
|
19
|
+
alternatives: string[];
|
|
20
|
+
reason: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const STAGE4_NAME: RegExp;
|
|
23
|
+
/** Options that coincide only in this data set are a declaration, not a pseudo-choice. */
|
|
24
|
+
export declare const EQUIVALENT_REASON: RegExp;
|
|
25
|
+
export declare function isStage4(name: string): boolean;
|
|
26
|
+
export declare function settledBy(label: PriorLabel, reason: string): "intent" | "convention" | "equivalent";
|
|
27
|
+
/** "value | other — why" → alternatives and reason. Mirrors the labels splitter. */
|
|
28
|
+
export declare function splitLabel(text: string): {
|
|
29
|
+
alternatives: string[];
|
|
30
|
+
reason: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function parseConstants(source: string): PriorConstant[];
|
|
33
|
+
export declare function optionIds(constant: PriorConstant): string[];
|