@mmon-co/ncept-default-theory 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/catalog-contract.d.ts +102 -0
- package/dist/catalog-contract.js +75 -0
- package/dist/catalog.d.ts +14 -0
- package/dist/catalog.js +164 -0
- package/dist/chat.d.ts +171 -0
- package/dist/chat.js +232 -0
- package/dist/completion.d.ts +74 -0
- package/dist/completion.js +277 -0
- package/dist/dependent-cone.d.ts +3 -0
- package/dist/dependent-cone.js +26 -0
- package/dist/diagnosis.d.ts +9 -0
- package/dist/diagnosis.js +1 -0
- package/dist/diagnostics.d.ts +25 -0
- package/dist/diagnostics.js +34 -0
- package/dist/evaluation.d.ts +33 -0
- package/dist/evaluation.js +376 -0
- package/dist/event.d.ts +7 -0
- package/dist/event.js +405 -0
- package/dist/history.d.ts +4 -0
- package/dist/history.js +61 -0
- package/dist/implementation.d.ts +184 -0
- package/dist/implementation.js +31 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +27 -0
- package/dist/messages.d.ts +167 -0
- package/dist/messages.js +56 -0
- package/dist/opening.d.ts +20 -0
- package/dist/opening.js +33 -0
- package/dist/outcomes.d.ts +143 -0
- package/dist/outcomes.js +323 -0
- package/dist/path.d.ts +19 -0
- package/dist/path.js +293 -0
- package/dist/reading.d.ts +12 -0
- package/dist/reading.js +75 -0
- package/dist/release.d.ts +1 -0
- package/dist/release.js +1 -0
- package/dist/roleplay.d.ts +17 -0
- package/dist/roleplay.js +2 -0
- package/dist/skills/sources.d.ts +12 -0
- package/dist/skills/sources.js +13 -0
- package/dist/skills.d.ts +12 -0
- package/dist/skills.js +70 -0
- package/dist/state.d.ts +316 -0
- package/dist/state.js +1309 -0
- package/dist/tags.d.ts +34 -0
- package/dist/tags.js +306 -0
- package/dist/timing.d.ts +21 -0
- package/dist/timing.js +79 -0
- package/dist/tools.d.ts +394 -0
- package/dist/tools.js +872 -0
- package/package.json +52 -4
package/dist/tags.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type NodeId, type ResolvedGraph } from "@mmon-co/ncept-core/patch";
|
|
2
|
+
import type { ObservationId } from "@mmon-co/ncept-core/observations";
|
|
3
|
+
import type { TheoryProjection } from "@mmon-co/ncept-core/theory";
|
|
4
|
+
import { type DefaultState, type NodeState } from "./state.js";
|
|
5
|
+
export declare function defaultNodeState(state: DefaultState, node: NodeId): NodeState;
|
|
6
|
+
export declare function isDefaultKnown(node: NodeState): boolean;
|
|
7
|
+
/** Acquisition withdrawal does not discard a completion-bound Node’s recall schedule. */
|
|
8
|
+
export declare function isDefaultReviewable(node: NodeState): boolean;
|
|
9
|
+
/** A shared reachability answer travels in, so a projection walks the graph for it once. */
|
|
10
|
+
type QueryToken = (state: DefaultState, graph: ResolvedGraph, reached?: ReadonlySet<NodeId>) => ReadonlySet<NodeId>;
|
|
11
|
+
export declare const defaultQueryTokens: {
|
|
12
|
+
known: QueryToken;
|
|
13
|
+
demonstrated: QueryToken;
|
|
14
|
+
"probably-known": QueryToken;
|
|
15
|
+
unknown: QueryToken;
|
|
16
|
+
claimed: QueryToken;
|
|
17
|
+
unclaimed: QueryToken;
|
|
18
|
+
reachable: (state: DefaultState, graph: ResolvedGraph, reached?: ReadonlySet<`node-${string}`> | undefined) => ReadonlySet<`node-${string}`>;
|
|
19
|
+
frontier: (state: DefaultState, graph: ResolvedGraph, reached?: ReadonlySet<`node-${string}`> | undefined) => Set<`node-${string}`>;
|
|
20
|
+
"review:due": QueryToken;
|
|
21
|
+
"review:fading": QueryToken;
|
|
22
|
+
};
|
|
23
|
+
export interface Indicator {
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
readonly nodes: readonly NodeId[];
|
|
26
|
+
readonly citations: readonly ObservationId[];
|
|
27
|
+
readonly message: string;
|
|
28
|
+
}
|
|
29
|
+
/** Display and query tags share exactly the same membership predicates. */
|
|
30
|
+
export declare const defaultTags: readonly [...string[], "item-outcomes", "instability", "unused", "coarse", "lesson-split", "self-report", "edge-contradiction", "homeless"];
|
|
31
|
+
export declare function indicatorsDefault(state: DefaultState, graph: ResolvedGraph): readonly Indicator[];
|
|
32
|
+
/** Only output assembly, continuous decay ranks and review membership vary within a boundary. */
|
|
33
|
+
export declare function projectDefault(graph: ResolvedGraph, state: DefaultState): TheoryProjection;
|
|
34
|
+
export {};
|
package/dist/tags.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { dependentCones } from "./dependent-cone.js";
|
|
2
|
+
import { nodePriority, teachingPath, pathProperty, nodeAllowsReview } from "./path.js";
|
|
3
|
+
import { NODE_ELABORATE_PROPERTY } from "@mmon-co/ncept-core/patch";
|
|
4
|
+
import { completionCaption } from "./completion.js";
|
|
5
|
+
import { defaultProjectionBasis, DEFAULT_PARAMETERS, } from "./state.js";
|
|
6
|
+
export function defaultNodeState(state, node) {
|
|
7
|
+
const value = state.nodes[node];
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
throw new Error(`Node ${node} has not been projected`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
export function isDefaultKnown(node) {
|
|
13
|
+
return node.label === "demonstrated" || node.label === "probably-known";
|
|
14
|
+
}
|
|
15
|
+
/** Acquisition withdrawal does not discard a completion-bound Node’s recall schedule. */
|
|
16
|
+
export function isDefaultReviewable(node) {
|
|
17
|
+
return isDefaultKnown(node) || (node.completion.query !== undefined && node.schedule !== undefined);
|
|
18
|
+
}
|
|
19
|
+
function select(predicate) {
|
|
20
|
+
return (state, graph) => new Set(graph.nodes.filter(({ id }) => predicate(defaultNodeState(state, id), graph, id)).map(({ id }) => id));
|
|
21
|
+
}
|
|
22
|
+
function reachableNodes(state, graph) {
|
|
23
|
+
return new Set(graph.nodes
|
|
24
|
+
.filter(({ id }) => graph.edges.filter(({ to }) => to === id).every(({ from }) => isDefaultKnown(defaultNodeState(state, from))))
|
|
25
|
+
.map(({ id }) => id));
|
|
26
|
+
}
|
|
27
|
+
export const defaultQueryTokens = {
|
|
28
|
+
known: select(isDefaultKnown),
|
|
29
|
+
demonstrated: select((node) => node.label === "demonstrated"),
|
|
30
|
+
"probably-known": select((node) => node.label === "probably-known"),
|
|
31
|
+
unknown: select((node) => node.label === "unknown"),
|
|
32
|
+
claimed: select((node) => {
|
|
33
|
+
const latest = node.records.findLast(({ payload }) => payload.kind === "claim");
|
|
34
|
+
return latest?.payload.kind === "claim" && latest.payload.stance === "knows";
|
|
35
|
+
}),
|
|
36
|
+
unclaimed: select((node) => {
|
|
37
|
+
const latest = node.records.findLast(({ payload }) => payload.kind === "claim");
|
|
38
|
+
return latest?.payload.kind === "claim" && latest.payload.stance !== "knows";
|
|
39
|
+
}),
|
|
40
|
+
reachable: (state, graph, reached = reachableNodes(state, graph)) => reached,
|
|
41
|
+
frontier: (state, graph, reached = reachableNodes(state, graph)) => new Set([...reached].filter((id) => !isDefaultKnown(defaultNodeState(state, id)))),
|
|
42
|
+
"review:due": select((node, graph, id) => nodeAllowsReview(graph, id) &&
|
|
43
|
+
!node.reviewCleared &&
|
|
44
|
+
isDefaultReviewable(node) &&
|
|
45
|
+
(node.schedule?.lapsed === true || (node.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.due)),
|
|
46
|
+
"review:fading": select((node, graph, id) => nodeAllowsReview(graph, id) &&
|
|
47
|
+
!node.reviewCleared &&
|
|
48
|
+
isDefaultReviewable(node) &&
|
|
49
|
+
(node.schedule?.lapsed === true || (node.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.fading)),
|
|
50
|
+
};
|
|
51
|
+
function demonstrations(records) {
|
|
52
|
+
return records.filter((record) => record.payload.kind === "demonstration");
|
|
53
|
+
}
|
|
54
|
+
/** Nodes whose latest `pedagogy:elaborate` contribution is `true`: left coarse at charting. */
|
|
55
|
+
function coarseNodes(graph) {
|
|
56
|
+
return new Set(graph.nodes.filter(({ id }) => pathProperty(graph, id, NODE_ELABORATE_PROPERTY) === true).map(({ id }) => id));
|
|
57
|
+
}
|
|
58
|
+
function prepareGraph(graph) {
|
|
59
|
+
const cone = dependentCones(graph);
|
|
60
|
+
const targets = graph.nodes.filter(({ id }) => !graph.edges.some((edge) => edge.from === id)).map(({ id }) => id);
|
|
61
|
+
return {
|
|
62
|
+
coarse: coarseNodes(graph),
|
|
63
|
+
cones: new Map(graph.nodes.map(({ id }) => [id, cone(id)])),
|
|
64
|
+
priority: new Map(graph.nodes.map(({ id }) => [id, nodePriority(graph, id)])),
|
|
65
|
+
warnings: teachingPath(graph, targets).warnings,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const graphPreparations = new WeakMap();
|
|
69
|
+
/** Facts only. Empty citations on absence indicators mean no evidence, not invented support. */
|
|
70
|
+
function computeIndicators(state, graph, facts) {
|
|
71
|
+
// Failure and "I don't know" weigh alike for mastery, so item and window comparisons see only success or not.
|
|
72
|
+
const succeeded = ({ payload }) => payload.outcome === "success";
|
|
73
|
+
const results = [];
|
|
74
|
+
function add(kind, nodes, records, message) {
|
|
75
|
+
results.push({
|
|
76
|
+
kind,
|
|
77
|
+
nodes,
|
|
78
|
+
citations: [...new Set(records.map(({ id }) => id))],
|
|
79
|
+
message,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const coarse = facts.coarse;
|
|
83
|
+
for (const { id } of graph.nodes) {
|
|
84
|
+
const node = state.nodes[id];
|
|
85
|
+
if (node === undefined)
|
|
86
|
+
throw new Error(`Node ${id} has not been projected`);
|
|
87
|
+
const attempts = demonstrations(node.records);
|
|
88
|
+
// Task text is the default schema's item identity; formats are deliberately not standardized.
|
|
89
|
+
const tasks = [...new Set(attempts.map(({ payload }) => payload.task))];
|
|
90
|
+
for (const task of tasks) {
|
|
91
|
+
const item = attempts.filter(({ payload }) => payload.task === task);
|
|
92
|
+
if (item.length < 2)
|
|
93
|
+
continue;
|
|
94
|
+
const constant = item.every((record) => succeeded(record) === succeeded(item[0] ?? record));
|
|
95
|
+
const peers = tasks
|
|
96
|
+
.filter((other) => other !== task)
|
|
97
|
+
.flatMap((other) => {
|
|
98
|
+
const records = attempts.filter(({ payload }) => payload.task === other);
|
|
99
|
+
return records.length === item.length &&
|
|
100
|
+
records.every((record, index) => succeeded(record) === succeeded(item[index] ?? record) && item[index] !== undefined)
|
|
101
|
+
? records
|
|
102
|
+
: [];
|
|
103
|
+
});
|
|
104
|
+
if (constant || peers.length > 0)
|
|
105
|
+
add("item-outcomes", [id], [...item, ...peers], `Task ${JSON.stringify(task)}: ${constant ? "observed outcomes never differ" : "outcome sequence matches other items"}`);
|
|
106
|
+
}
|
|
107
|
+
const window = attempts.filter(({ payload }) => payload.unaided).slice(-3);
|
|
108
|
+
if (window.length >= 3 &&
|
|
109
|
+
window.every((record, index) => index === 0 || succeeded(record) !== succeeded(window[index - 1] ?? record)))
|
|
110
|
+
add("instability", [id], window, "Outcomes alternate across the observed window");
|
|
111
|
+
if (coarse.has(id))
|
|
112
|
+
add("coarse", [id], [], "Left coarse at charting: its prerequisites are not charted yet");
|
|
113
|
+
// Candidate absence is evidence-only; completion credit filters these candidates separately.
|
|
114
|
+
const used = (dependent) => (state.nodes[dependent]?.records.length ?? 0) > 0;
|
|
115
|
+
if (!used(id) && (facts.cones.get(id) ?? []).every((dependent) => !used(dependent)))
|
|
116
|
+
add("unused", [id], [], "No records on this Node or its dependents");
|
|
117
|
+
const graded = attempts.filter(({ payload }) => payload.grader !== "learner");
|
|
118
|
+
for (const report of node.records) {
|
|
119
|
+
const outcome = report.payload.kind === "claim"
|
|
120
|
+
? report.payload.stance === "knows"
|
|
121
|
+
? "success"
|
|
122
|
+
: "failure"
|
|
123
|
+
: report.payload.grader === "learner"
|
|
124
|
+
? report.payload.outcome === "success"
|
|
125
|
+
? "success"
|
|
126
|
+
: "failure"
|
|
127
|
+
: undefined;
|
|
128
|
+
if (outcome === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
const contradictions = graded.filter(({ payload }) => payload.outcome !== outcome);
|
|
131
|
+
if (contradictions.length > 0)
|
|
132
|
+
add("self-report", [id], [report, ...contradictions], "Self-report and tutor/mechanical outcomes differ on this Node");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const edge of graph.edges) {
|
|
136
|
+
const successes = demonstrations(state.nodes[edge.to]?.records ?? []).filter(({ payload }) => payload.unaided && payload.outcome === "success");
|
|
137
|
+
const failures = demonstrations(state.nodes[edge.from]?.records ?? []).filter(({ payload }) => payload.unaided && payload.outcome !== "success");
|
|
138
|
+
for (const failure of failures) {
|
|
139
|
+
const earlier = successes.filter((success) => Date.parse(success.at) < Date.parse(failure.at));
|
|
140
|
+
if (earlier.length > 0)
|
|
141
|
+
add("edge-contradiction", [edge.from, edge.to], [...earlier, failure], `Unaided prerequisite failure after dependent success on ${edge.id}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const record of state.homeless)
|
|
145
|
+
add("homeless", [], [record], "Record has no home after Patch revision");
|
|
146
|
+
for (const warning of facts.warnings)
|
|
147
|
+
add(warning.kind, warning.nodes, [], `Lesson ${warning.name} splits around a section or outside blocker`);
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
/** Display and query tags share exactly the same membership predicates. */
|
|
151
|
+
export const defaultTags = [
|
|
152
|
+
...Object.keys(defaultQueryTokens),
|
|
153
|
+
"item-outcomes",
|
|
154
|
+
"instability",
|
|
155
|
+
"unused",
|
|
156
|
+
"coarse",
|
|
157
|
+
"lesson-split",
|
|
158
|
+
"self-report",
|
|
159
|
+
"edge-contradiction",
|
|
160
|
+
"homeless",
|
|
161
|
+
];
|
|
162
|
+
function indicatorTag(indicator) {
|
|
163
|
+
return { tag: indicator.kind, caption: indicator.message, cites: indicator.citations };
|
|
164
|
+
}
|
|
165
|
+
function nodeProgressMessage(node) {
|
|
166
|
+
const hasSuccess = node.lastSuccess !== undefined;
|
|
167
|
+
const counts = completionCaption(node.completion);
|
|
168
|
+
const only = node.completion.counts.length === 1 ? node.completion.counts[0] : undefined;
|
|
169
|
+
return {
|
|
170
|
+
id: hasSuccess ? "default.node-progress.last-success" : "default.node-progress.no-success",
|
|
171
|
+
defaultMessage: hasSuccess
|
|
172
|
+
? "{counts}last success {lastSuccess}; aided practice {aidedPractice}"
|
|
173
|
+
: "{counts}last success none; aided practice {aidedPractice}",
|
|
174
|
+
values: {
|
|
175
|
+
counts: counts
|
|
176
|
+
? {
|
|
177
|
+
type: "message",
|
|
178
|
+
message: { id: "default.node-progress.counts", defaultMessage: "{counts}, ", values: { counts } },
|
|
179
|
+
}
|
|
180
|
+
: "",
|
|
181
|
+
aidedPractice: node.aidedPractice,
|
|
182
|
+
...(only === undefined ? {} : { k: only.k, required: only.required }),
|
|
183
|
+
...(node.lastSuccess === undefined ? {} : { lastSuccess: { type: "date", value: node.lastSuccess } }),
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Evidence/label facts are retained separately from decay and review membership. Weak keys belong
|
|
188
|
+
* to a reducer's snapshots, so preparations cannot outlive that read context. */
|
|
189
|
+
function prepareProjection(graph, state, facts, evidenceIndicators = computeIndicators(state, graph, facts)) {
|
|
190
|
+
const indicators = evidenceIndicators.filter((indicator) => indicator.kind !== "unused" ||
|
|
191
|
+
indicator.nodes.every((id) => [id, ...(facts.cones.get(id) ?? [])].every((node) => (state.nodes[node]?.completion.citations.length ?? 0) === 0)));
|
|
192
|
+
const reached = reachableNodes(state, graph);
|
|
193
|
+
const selected = Object.entries(defaultQueryTokens)
|
|
194
|
+
.filter(([tag]) => !tag.startsWith("review:"))
|
|
195
|
+
.map(([tag, select]) => [tag, select(state, graph, reached)]);
|
|
196
|
+
const perNode = new Map();
|
|
197
|
+
for (const indicator of indicators) {
|
|
198
|
+
const tag = indicatorTag(indicator);
|
|
199
|
+
for (const node of new Set(indicator.nodes)) {
|
|
200
|
+
const bucket = perNode.get(node);
|
|
201
|
+
if (bucket === undefined)
|
|
202
|
+
perNode.set(node, [tag]);
|
|
203
|
+
else
|
|
204
|
+
bucket.push(tag);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const contradictions = indicators.filter(({ kind }) => kind === "edge-contradiction");
|
|
208
|
+
const nodes = new Map(graph.nodes.map(({ id }) => {
|
|
209
|
+
const node = defaultNodeState(state, id);
|
|
210
|
+
const assessment = {
|
|
211
|
+
tag: node.label,
|
|
212
|
+
caption: completionCaption(node.completion),
|
|
213
|
+
message: nodeProgressMessage(node),
|
|
214
|
+
cites: node.citations,
|
|
215
|
+
};
|
|
216
|
+
const tags = selected.flatMap(([tag, members]) => tag !== node.label && members.has(id) ? [{ tag, cites: node.citations }] : []);
|
|
217
|
+
const reviewRank = (facts.priority.get(id) ?? 0) * (graph.nodes.length + 1) +
|
|
218
|
+
(facts.cones.get(id) ?? []).filter((dependent) => !isDefaultKnown(defaultNodeState(state, dependent))).length;
|
|
219
|
+
return [id, { assessment, tags, reviewRank }];
|
|
220
|
+
}));
|
|
221
|
+
const edges = {};
|
|
222
|
+
for (const edge of graph.edges) {
|
|
223
|
+
const dependent = defaultNodeState(state, edge.to);
|
|
224
|
+
const prerequisite = defaultNodeState(state, edge.from);
|
|
225
|
+
const gating = !isDefaultKnown(prerequisite) && !isDefaultKnown(dependent);
|
|
226
|
+
const frontier = isDefaultKnown(prerequisite) && !isDefaultKnown(dependent);
|
|
227
|
+
const cites = [...new Set([...dependent.citations, ...prerequisite.citations])];
|
|
228
|
+
edges[edge.id] = [
|
|
229
|
+
{
|
|
230
|
+
tag: gating ? "gating" : "not-gating",
|
|
231
|
+
caption: gating ? "Prerequisite not known" : frontier ? "Frontier" : "Not gating",
|
|
232
|
+
cites,
|
|
233
|
+
},
|
|
234
|
+
...(frontier ? [{ tag: "frontier", cites }] : []),
|
|
235
|
+
// An indicator names the Nodes it is about; an Edge it is about is named only in its message.
|
|
236
|
+
...contradictions.filter(({ message }) => message.endsWith(`on ${edge.id}`)).map(indicatorTag),
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
return { indicators, perNode, nodes, edges, learner: indicators.map(indicatorTag) };
|
|
240
|
+
}
|
|
241
|
+
const evidencePreparations = new WeakMap();
|
|
242
|
+
const indicatorPreparations = new WeakMap();
|
|
243
|
+
function preparedProjection(graph, state) {
|
|
244
|
+
const basis = defaultProjectionBasis(state);
|
|
245
|
+
if (basis === undefined || basis.graph !== graph)
|
|
246
|
+
return prepareProjection(graph, state, prepareGraph(graph));
|
|
247
|
+
let prepared = evidencePreparations.get(basis.evidenceKey);
|
|
248
|
+
if (prepared !== undefined)
|
|
249
|
+
return prepared;
|
|
250
|
+
let facts = graphPreparations.get(basis.graphKey);
|
|
251
|
+
if (facts === undefined) {
|
|
252
|
+
facts = prepareGraph(graph);
|
|
253
|
+
graphPreparations.set(basis.graphKey, facts);
|
|
254
|
+
}
|
|
255
|
+
let indicators = indicatorPreparations.get(basis.indicatorKey);
|
|
256
|
+
if (indicators === undefined) {
|
|
257
|
+
indicators = computeIndicators(state, graph, facts);
|
|
258
|
+
indicatorPreparations.set(basis.indicatorKey, indicators);
|
|
259
|
+
}
|
|
260
|
+
prepared = prepareProjection(graph, state, facts, indicators);
|
|
261
|
+
evidencePreparations.set(basis.evidenceKey, prepared);
|
|
262
|
+
return prepared;
|
|
263
|
+
}
|
|
264
|
+
export function indicatorsDefault(state, graph) {
|
|
265
|
+
return preparedProjection(graph, state).indicators;
|
|
266
|
+
}
|
|
267
|
+
/** Only output assembly, continuous decay ranks and review membership vary within a boundary. */
|
|
268
|
+
export function projectDefault(graph, state) {
|
|
269
|
+
const prepared = preparedProjection(graph, state);
|
|
270
|
+
const reviews = Object.entries(defaultQueryTokens)
|
|
271
|
+
.filter(([tag]) => tag.startsWith("review:"))
|
|
272
|
+
.map(([tag, select]) => [tag, select(state, graph)]);
|
|
273
|
+
const nodes = {};
|
|
274
|
+
for (const { id } of graph.nodes) {
|
|
275
|
+
const node = defaultNodeState(state, id);
|
|
276
|
+
const facts = prepared.nodes.get(id);
|
|
277
|
+
if (facts === undefined)
|
|
278
|
+
throw new Error("Missing prepared default projection");
|
|
279
|
+
nodes[id] = [
|
|
280
|
+
{
|
|
281
|
+
...facts.assessment,
|
|
282
|
+
...(isDefaultKnown(node) && node.schedule ? { rank: node.schedule.retrievability } : {}),
|
|
283
|
+
},
|
|
284
|
+
...facts.tags,
|
|
285
|
+
...reviews.flatMap(([tag, members]) => members.has(id)
|
|
286
|
+
? [
|
|
287
|
+
{
|
|
288
|
+
tag,
|
|
289
|
+
rank: facts.reviewRank + 1 - (node.schedule?.retrievability ?? 1),
|
|
290
|
+
cites: node.schedule?.citations,
|
|
291
|
+
},
|
|
292
|
+
]
|
|
293
|
+
: []),
|
|
294
|
+
...(prepared.perNode.get(id) ?? []),
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
const expiry = Object.values(state.nodes)
|
|
298
|
+
.flatMap((node) => (node?.completion.validUntil !== undefined ? [node.completion.validUntil] : []))
|
|
299
|
+
.sort((a, b) => Date.parse(a) - Date.parse(b))[0];
|
|
300
|
+
return {
|
|
301
|
+
nodes,
|
|
302
|
+
edges: prepared.edges,
|
|
303
|
+
learner: prepared.learner,
|
|
304
|
+
...(expiry === undefined ? {} : { validUntil: expiry }),
|
|
305
|
+
};
|
|
306
|
+
}
|
package/dist/timing.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ResolvedGraph } from "@mmon-co/ncept-core/patch";
|
|
2
|
+
import type { Observation } from "@mmon-co/ncept-core/observations";
|
|
3
|
+
import type { LessonActivity } from "@mmon-co/ncept-core/theory";
|
|
4
|
+
export type LessonTiming = Readonly<{
|
|
5
|
+
minutesPerNode: number;
|
|
6
|
+
rough: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const UNMEASURED_LESSON_TIMING: LessonTiming;
|
|
9
|
+
export declare const UNMEASURED_REVIEW_TIMING: LessonTiming;
|
|
10
|
+
/** Unique unaided checks in Review Sessions; acquisition already predates these checks. */
|
|
11
|
+
export declare function measuredReviewTiming(observations: readonly Observation[], activities: readonly LessonActivity[]): LessonTiming;
|
|
12
|
+
/** Actual demonstration transitions, not attempts or currently-known Nodes. The fold sees the
|
|
13
|
+
* evidence at its recording time, so forgetting after a lesson does not erase the measurement.
|
|
14
|
+
*/
|
|
15
|
+
export declare function measuredLessonTiming(graph: ResolvedGraph, observations: readonly Observation[], activities: readonly LessonActivity[]): LessonTiming;
|
|
16
|
+
/** One reading's resumable recording-time scan. Roughness needs only its first transition;
|
|
17
|
+
* acquisition timing needs the complete unique (teaching surface, Node) denominator. */
|
|
18
|
+
export declare function prepareLessonTiming(graph: ResolvedGraph, observations: readonly Observation[], activities: readonly LessonActivity[]): {
|
|
19
|
+
rough: () => boolean;
|
|
20
|
+
measure(): LessonTiming;
|
|
21
|
+
};
|
package/dist/timing.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isNodeId } from "@mmon-co/ncept-core/patch";
|
|
2
|
+
import { isDemonstration, initDefaultState } from "./state.js";
|
|
3
|
+
export const UNMEASURED_LESSON_TIMING = { minutesPerNode: 20, rough: true };
|
|
4
|
+
export const UNMEASURED_REVIEW_TIMING = { minutesPerNode: 2, rough: true };
|
|
5
|
+
/** Unique unaided checks in Review Sessions; acquisition already predates these checks. */
|
|
6
|
+
export function measuredReviewTiming(observations, activities) {
|
|
7
|
+
const reviews = activities.filter((activity) => activity.stop?.kind === "review");
|
|
8
|
+
const surfaces = new Map(reviews.flatMap((activity) => [activity.surface, ...(activity.relatedSurfaces ?? [])].map((surface) => [surface, activity])));
|
|
9
|
+
const reviewed = new Set();
|
|
10
|
+
for (const observation of observations) {
|
|
11
|
+
const activity = observation.surface === undefined ? undefined : surfaces.get(observation.surface);
|
|
12
|
+
if (!activity || observation.at < activity.startedAt || observation.standing === "abandoned")
|
|
13
|
+
continue;
|
|
14
|
+
const payload = observation.payload;
|
|
15
|
+
if (isDemonstration(payload) && payload.unaided && activity.stop?.nodes?.includes(payload.node.node))
|
|
16
|
+
reviewed.add(activity.surface + "/" + payload.node.node);
|
|
17
|
+
}
|
|
18
|
+
const activeMs = reviews.reduce((sum, activity) => sum + activity.activeMs, 0);
|
|
19
|
+
return reviewed.size && activeMs > 0
|
|
20
|
+
? { minutesPerNode: activeMs / 60_000 / reviewed.size, rough: false }
|
|
21
|
+
: UNMEASURED_REVIEW_TIMING;
|
|
22
|
+
}
|
|
23
|
+
/** Actual demonstration transitions, not attempts or currently-known Nodes. The fold sees the
|
|
24
|
+
* evidence at its recording time, so forgetting after a lesson does not erase the measurement.
|
|
25
|
+
*/
|
|
26
|
+
export function measuredLessonTiming(graph, observations, activities) {
|
|
27
|
+
return prepareLessonTiming(graph, observations, activities).measure();
|
|
28
|
+
}
|
|
29
|
+
/** One reading's resumable recording-time scan. Roughness needs only its first transition;
|
|
30
|
+
* acquisition timing needs the complete unique (teaching surface, Node) denominator. */
|
|
31
|
+
export function prepareLessonTiming(graph, observations, activities) {
|
|
32
|
+
const teaching = activities.filter((activity) => activity.stop?.kind !== "review");
|
|
33
|
+
const lessonSurfaces = new Map(teaching.map((activity) => [activity.surface, activity]));
|
|
34
|
+
const demonstrated = new Set();
|
|
35
|
+
function* transitions() {
|
|
36
|
+
const state = initDefaultState(graph);
|
|
37
|
+
let consumed = 0;
|
|
38
|
+
for (const [index, observation] of observations.entries()) {
|
|
39
|
+
const activity = observation.surface === undefined ? undefined : lessonSurfaces.get(observation.surface);
|
|
40
|
+
if (activity === undefined || observation.at < activity.startedAt || observation.standing === "abandoned")
|
|
41
|
+
continue;
|
|
42
|
+
// Skipped evidence still belongs to the prefix, but never to this activity's denominator.
|
|
43
|
+
if (consumed < index)
|
|
44
|
+
state.step(observations.slice(consumed, index));
|
|
45
|
+
const before = state.read(observation.at);
|
|
46
|
+
state.step([observation]);
|
|
47
|
+
consumed = index + 1;
|
|
48
|
+
const after = state.read(observation.at);
|
|
49
|
+
for (const [id, node] of Object.entries(after.nodes))
|
|
50
|
+
if (isNodeId(id) && node?.label === "demonstrated" && before.nodes[id]?.label !== "demonstrated")
|
|
51
|
+
demonstrated.add(activity.surface + "/" + id);
|
|
52
|
+
if (demonstrated.size)
|
|
53
|
+
yield;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const scan = transitions();
|
|
57
|
+
const activeMs = teaching.reduce((sum, activity) => sum + activity.activeMs, 0);
|
|
58
|
+
const rough = () => {
|
|
59
|
+
// Single-turn lessons have no gaps; zero active time is already unmeasured.
|
|
60
|
+
if (activeMs <= 0)
|
|
61
|
+
return true;
|
|
62
|
+
if (!demonstrated.size)
|
|
63
|
+
scan.next();
|
|
64
|
+
return !demonstrated.size;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
rough,
|
|
68
|
+
measure() {
|
|
69
|
+
if (activeMs <= 0)
|
|
70
|
+
return UNMEASURED_LESSON_TIMING;
|
|
71
|
+
while (!scan.next().done) {
|
|
72
|
+
/* Finish or resume the same scan. */
|
|
73
|
+
}
|
|
74
|
+
return demonstrated.size
|
|
75
|
+
? { minutesPerNode: activeMs / 60_000 / demonstrated.size, rough: false }
|
|
76
|
+
: UNMEASURED_LESSON_TIMING;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|