@mmon-co/ncept-local 0.3.6 → 0.3.7
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/README.md +3 -4
- package/dist/directory.js +7 -4
- package/dist/exchange.d.ts +2 -0
- package/dist/exchange.js +62 -7
- package/dist/host-tools.js +4 -13
- package/dist/host.d.ts +0 -2
- package/dist/inputs.d.ts +1 -0
- package/dist/inputs.js +1 -31
- package/dist/learning.d.ts +8 -5
- package/dist/learning.js +104 -163
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ await unpackDirectory(tar, "/path/to/moved-profile", [defaultTheory]);
|
|
|
17
17
|
|
|
18
18
|
`init` creates an empty personal Patch, empty log and reserved directories in an ordinary project directory. `profile.json` contains `format: 1`, `personal`, `theory` (Core's requirement), `theories` (package names, initially `@mmon-co/ncept-default-theory`) and `sessions` (surface → pi filename). Account credentials live at `credentialsPath()`, outside the Profile, in `~/.config/ncept/credentials.json`.
|
|
19
19
|
|
|
20
|
-
`openProfile` and `unpack` migrate a stored minor pin (or an exact web-export release) with the supplied executable Theory’s `migrations` before strict resolution. Broad requirements still use strict resolution without migration. Migration writes new immutable Patch revisions and a content-addressed log snapshot, then atomically switches `profile.json`’s personal head, Theory requirement and optional `log` digest together. Interrupted writes leave the old generation active; reopening retries pure steps from that generation. Old revision/log files remain unread history. Host futures are rebuilt from the migrated Profile; captured Session transcripts are not rewritten as futures.
|
|
20
|
+
`openProfile` and `unpack` migrate a stored minor pin (or an exact web-export release) with the supplied executable Theory’s `migrations` before strict resolution. Broad requirements still use strict resolution without migration. Migration writes new immutable Patch revisions and a content-addressed log snapshot, then atomically switches `profile.json`’s personal head, Theory requirement and optional `log` digest together. Interrupted writes leave the old generation active; reopening retries pure steps from that generation. Old revision/log files remain unread history. Opening a Profile also upgrades its host log: Lesson Sessions are entered on their Mission and run entries no longer retain a stop. The read-only Learn panel performs this log upgrade when it first opens an older Profile. Host futures are rebuilt from the migrated Profile; captured Session transcripts are not rewritten as futures.
|
|
21
21
|
|
|
22
22
|
`openProfile` verifies digests, the personal Patch's complete base closure, log envelopes and the configured Theory range. Its handle appends log identities, adds immutable revisions and blobs, changes the personal head, and registers trusted transcripts. Add attachment bytes before revisions referring to them. A new revision replaces its identity's prior content; its bases are other Patches, not its own history.
|
|
23
23
|
|
|
@@ -31,17 +31,16 @@ Import `@mmon-co/ncept-local/exchange` in Convex actions or browsers; it has no
|
|
|
31
31
|
|
|
32
32
|
`openHost({ profileDir, theories, model, confirm })` runs the selected Theory over the directory. The front end supplies constrained JSON replies for `judge` and `assess` (including decision grading), confirms proposals, and carries out the conversation/carry in a returned mode switch. Native catalog members are mounted by their original names; the web's envelopes remain unchanged. `web` and `bash` are the front end's capabilities, not tools implemented here. `host.hub` connects to the hosted Hub over anonymous HTTP and authenticated MCP.
|
|
33
33
|
|
|
34
|
-
Open a Session with `host.sessions.open({ mode, entry })`, then call `.turn(session, {})` for its prompt, context, Skills and bound tools. The default Theory's modes are `empty`, `charting` (entries `goal`, `mission`, `target`, `checkpoint`), `authoring` and `lesson` (entries `
|
|
34
|
+
Open a Session with `host.sessions.open({ mode, entry })`, then call `.turn(session, {})` for its prompt, context, Skills and bound tools. The default Theory's modes are `empty`, `charting` (entries `goal`, `mission`, `target`, `checkpoint`), `authoring` and `lesson` (entries `mission`, `target`, `review`); the turn's `context` lists each mode's entry kinds and allowed switches. A tool is `{ name, description, schema, run(input) }`:
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
37
|
const session = await host.sessions.open({ mode: "charting", entry: { kind: "goal", text: "Learn addition" } });
|
|
38
38
|
const setup = await host.sessions.turn(session, {});
|
|
39
39
|
const claim = setup.tools.find((tool) => tool.name === "record_claim")!;
|
|
40
40
|
await claim.run({ statement: "I can add one and one", stance: "knows" });
|
|
41
|
-
const next = await host.sessions.settle(session);
|
|
42
41
|
```
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
A Lesson Session entered on a Mission reads the first uncleared numbered Lesson on the Mission's path each turn. When that Lesson clears, the same Session can teach the next one.
|
|
45
44
|
|
|
46
45
|
After a switch result, call `.open(result.switch)` for `next`/`aside`; for `here`, keep the same Session handle and request a fresh turn. `.close(session)` records its closing transcript through the Theory. Resume a closed Session with `.open({ mode, resume: session.id })`. Session identities, mode, scope, acceptance provenance and learner-day receipts are platform observations in `log.jsonl`, so they travel with the Profile.
|
|
47
46
|
|
package/dist/directory.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join, resolve } from "node:path";
|
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { lock, lockSync } from "proper-lockfile";
|
|
6
6
|
import { attachmentDigest, candidateRevision, emptyPatch, isPatchId, mergeProfileLogs, PERSONAL_PATCH_ID, } from "@mmon-co/ncept-core";
|
|
7
|
-
import { DEFAULT_THEORY_PACKAGES, DEFAULT_THEORY_REQUIREMENT, jsonBytes, logBytes, liveLogPath, migrateProfileFiles, pack, parseManifest, sessionFilename, unpack, utf8, validate, } from "./exchange.js";
|
|
7
|
+
import { DEFAULT_THEORY_PACKAGES, DEFAULT_THEORY_REQUIREMENT, jsonBytes, logBytes, liveLogPath, migrateLessonLog, migrateProfileFiles, pack, parseManifest, sessionFilename, unpack, utf8, validate, } from "./exchange.js";
|
|
8
8
|
import { parsePiSession, piSessionFilename, relocatePiSession, serializePiSession, } from "./sessions.js";
|
|
9
9
|
/** Account credentials never belong to a Profile or its exchange tar. */
|
|
10
10
|
export function credentialsPath(home = homedir()) {
|
|
@@ -122,10 +122,12 @@ async function locked(dir, operation) {
|
|
|
122
122
|
}
|
|
123
123
|
export async function openProfile(dir, theories, options = {}) {
|
|
124
124
|
dir = resolve(dir);
|
|
125
|
-
|
|
125
|
+
const readOnlyFiles = options.readOnly ? await filesAt(dir) : undefined;
|
|
126
|
+
if (!readOnlyFiles || migrateLessonLog(readOnlyFiles) !== readOnlyFiles)
|
|
126
127
|
await locked(dir, async () => {
|
|
127
128
|
const stored = await filesAt(dir);
|
|
128
|
-
const initial = migrateProfileFiles(stored, theories);
|
|
129
|
+
const initial = options.readOnly ? migrateLessonLog(stored) : migrateProfileFiles(stored, theories);
|
|
130
|
+
const profile = validate(initial, theories);
|
|
129
131
|
// Immutable data first, then a single atomic live-head/log/pin switch. An interruption
|
|
130
132
|
// leaves either the old generation or the complete new one; retry never repeats a step.
|
|
131
133
|
for (const [path, bytes] of initial) {
|
|
@@ -135,7 +137,8 @@ export async function openProfile(dir, theories, options = {}) {
|
|
|
135
137
|
const manifest = initial.get("profile.json");
|
|
136
138
|
if (manifest !== stored.get("profile.json") && manifest)
|
|
137
139
|
await atomic(dir, "profile.json", manifest);
|
|
138
|
-
|
|
140
|
+
if (options.readOnly)
|
|
141
|
+
return;
|
|
139
142
|
// A copied or moved Profile must still appear in pi's cwd-filtered /resume list.
|
|
140
143
|
for (const filename of Object.values(profile.manifest.sessions)) {
|
|
141
144
|
const path = "sessions/" + filename;
|
package/dist/exchange.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare function logBytes(entries: readonly ProfileLogEntry[]): Uint8Arra
|
|
|
30
30
|
/** Pure validation; safe in a Convex action. No filesystem, package loading, or provider calls. */
|
|
31
31
|
export declare function validate(files: ProfileFiles, theories: readonly ConfiguredTheory[]): ValidatedProfile;
|
|
32
32
|
export declare function liveLogPath(manifest: ProfileManifest): string;
|
|
33
|
+
/** Rewrite host-owned state before validating the log in its current shape. */
|
|
34
|
+
export declare function migrateLessonLog(files: ProfileFiles): ProfileFiles;
|
|
33
35
|
/** Migrate structurally valid live data before ordinary strict Theory resolution. */
|
|
34
36
|
export declare function migrateProfileFiles(files: ProfileFiles, theories: readonly ConfiguredTheory[]): Map<string, Uint8Array>;
|
|
35
37
|
/** Only exchange files belong in this map. The directory adapter excludes materials and untrusted sessions. */
|
package/dist/exchange.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attachmentDigest, resolveNotebookRevision, isContentDigest, isPatchId, isProfileLogEntry, mergeProfileLogs, migrateTheoryProfile, resolveTheory, revisionDigest, } from "@mmon-co/ncept-core";
|
|
1
|
+
import { attachmentDigest, resolveNotebookRevision, isContentDigest, isMissionRevision, isNodeId, isPatchId, isProfileLogEntry, mergeProfileLogs, migrateTheoryProfile, resolveTheory, revisionDigest, } from "@mmon-co/ncept-core";
|
|
2
2
|
import { object, parsePiSession, relocatePiSession } from "./sessions.js";
|
|
3
3
|
import { decodeTar, encodeTar } from "./tar.js";
|
|
4
4
|
export const DEFAULT_THEORY_PACKAGES = ["@mmon-co/ncept-default-theory"];
|
|
@@ -66,25 +66,31 @@ function patchContent(value) {
|
|
|
66
66
|
object(value.metadata.properties) &&
|
|
67
67
|
Array.isArray(value.metadata.citations));
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
function decodeLog(bytes) {
|
|
70
70
|
if (!bytes)
|
|
71
71
|
throw new Error("Missing Profile file: log.jsonl");
|
|
72
72
|
const lines = decoder.decode(bytes).split("\n");
|
|
73
73
|
if (lines.at(-1) === "")
|
|
74
74
|
lines.pop();
|
|
75
|
-
|
|
76
|
-
let value;
|
|
75
|
+
return lines.map((line, index) => {
|
|
77
76
|
try {
|
|
78
|
-
value = JSON.parse(line);
|
|
77
|
+
const value = JSON.parse(line);
|
|
78
|
+
return value;
|
|
79
79
|
}
|
|
80
80
|
catch {
|
|
81
81
|
throw new Error("Malformed Profile log JSON at line " + (index + 1));
|
|
82
82
|
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function checkedLog(entries) {
|
|
86
|
+
return mergeProfileLogs([], entries.map((value, index) => {
|
|
83
87
|
if (!isProfileLogEntry(value))
|
|
84
88
|
throw new Error("Invalid Profile log entry at line " + (index + 1));
|
|
85
89
|
return value;
|
|
86
|
-
});
|
|
87
|
-
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
export function parseLog(bytes) {
|
|
93
|
+
return checkedLog(decodeLog(bytes));
|
|
88
94
|
}
|
|
89
95
|
export function logBytes(entries) {
|
|
90
96
|
const merged = mergeProfileLogs([], entries);
|
|
@@ -156,8 +162,57 @@ function validateStructure(files) {
|
|
|
156
162
|
throw new Error("Profile log digest mismatch");
|
|
157
163
|
return { manifest, patches, log: parseLog(log), blobs, sessions };
|
|
158
164
|
}
|
|
165
|
+
/** Rewrite host-owned state before validating the log in its current shape. */
|
|
166
|
+
export function migrateLessonLog(files) {
|
|
167
|
+
const manifest = parseManifest(files.get("profile.json"));
|
|
168
|
+
const path = liveLogPath(manifest);
|
|
169
|
+
const bytes = files.get(path);
|
|
170
|
+
if (manifest.log !== undefined && (!bytes || attachmentDigest(bytes) !== manifest.log))
|
|
171
|
+
throw new Error("Profile log digest mismatch");
|
|
172
|
+
const entries = decodeLog(bytes);
|
|
173
|
+
const missions = new Set(entries.filter(isMissionRevision).map(({ mission }) => mission.id));
|
|
174
|
+
const nextEntries = entries.map((value) => {
|
|
175
|
+
if (!object(value))
|
|
176
|
+
return value;
|
|
177
|
+
if (value.kind === "run.past" && object(value.entry) && value.entry.kind === "session" && "stop" in value.entry) {
|
|
178
|
+
const { stop: _stop, ...entry } = value.entry;
|
|
179
|
+
return { ...value, entry };
|
|
180
|
+
}
|
|
181
|
+
const payload = value.payload;
|
|
182
|
+
if (value.by !== "platform" || !object(payload) || payload.kind !== "local.session" || !object(payload.session))
|
|
183
|
+
return value;
|
|
184
|
+
const { entry, mission: _mission, ...session } = payload.session;
|
|
185
|
+
if (!object(entry) || entry.kind !== "lesson" || !object(entry.lesson))
|
|
186
|
+
return value;
|
|
187
|
+
const lesson = entry.lesson;
|
|
188
|
+
const mission = object(lesson.mission) ? lesson.mission.id : undefined;
|
|
189
|
+
const node = Array.isArray(lesson.nodes) ? lesson.nodes.find(isNodeId) : undefined;
|
|
190
|
+
if (typeof mission === "string" && missions.has(mission)) {
|
|
191
|
+
return {
|
|
192
|
+
...value,
|
|
193
|
+
payload: { ...payload, session: { ...session, mission, entry: { kind: "mission", id: mission } } },
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (!node)
|
|
197
|
+
throw new Error("A detached Lesson needs a target Node");
|
|
198
|
+
return {
|
|
199
|
+
...value,
|
|
200
|
+
payload: { ...payload, session: { ...session, about: [node], entry: { kind: "target", node } } },
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
if (nextEntries.every((entry, index) => entry === entries[index]))
|
|
204
|
+
return files;
|
|
205
|
+
const next = new Map(files);
|
|
206
|
+
const log = logBytes(checkedLog(nextEntries));
|
|
207
|
+
const updated = { ...manifest, log: attachmentDigest(log) };
|
|
208
|
+
next.delete(path);
|
|
209
|
+
next.set(liveLogPath(updated), log);
|
|
210
|
+
next.set("profile.json", jsonBytes(updated));
|
|
211
|
+
return next;
|
|
212
|
+
}
|
|
159
213
|
/** Migrate structurally valid live data before ordinary strict Theory resolution. */
|
|
160
214
|
export function migrateProfileFiles(files, theories) {
|
|
215
|
+
files = migrateLessonLog(files);
|
|
161
216
|
const current = validateStructure(files);
|
|
162
217
|
const matches = theories.filter((theory) => theory.id === current.manifest.theory.theory);
|
|
163
218
|
const theory = matches[0];
|
package/dist/host-tools.js
CHANGED
|
@@ -4,7 +4,7 @@ import { applyGraphDiff, attachmentDigest, compileGraphDiff, composePatch, isMat
|
|
|
4
4
|
import { localPayload, platform, sessionStates, transcript } from "./runtime.js";
|
|
5
5
|
import { mechanics } from "./mechanics.js";
|
|
6
6
|
import { object } from "./sessions.js";
|
|
7
|
-
import { citations, exactRef, metadataProperties, modeEntry, operations, strings } from "./inputs.js";
|
|
7
|
+
import { citations, ENTRY_KINDS, exactRef, metadataProperties, modeEntry, operations, strings } from "./inputs.js";
|
|
8
8
|
function args(value) {
|
|
9
9
|
if (!object(value))
|
|
10
10
|
throw new Error("Expected an object");
|
|
@@ -241,14 +241,13 @@ export function hostTools(host, opened, capabilities, skills, metadataKeys) {
|
|
|
241
241
|
entry: {
|
|
242
242
|
type: "object",
|
|
243
243
|
properties: {
|
|
244
|
-
kind: { enum:
|
|
244
|
+
kind: { enum: ENTRY_KINDS },
|
|
245
245
|
text: string,
|
|
246
246
|
id: string,
|
|
247
247
|
node: string,
|
|
248
248
|
nodes: nodeList,
|
|
249
|
-
opening: schema({ missionId: string, number: { type: "integer", minimum: 1 } }, ["missionId"]),
|
|
250
249
|
},
|
|
251
|
-
description: "For
|
|
250
|
+
description: "For the current Lesson on a Mission, use {kind:'mission',id}.",
|
|
252
251
|
},
|
|
253
252
|
...graphProperties,
|
|
254
253
|
text: string,
|
|
@@ -266,15 +265,7 @@ export function hostTools(host, opened, capabilities, skills, metadataKeys) {
|
|
|
266
265
|
const allowed = selected?.switches.find((item) => item.mode === mode && (input.then === undefined || item.then === input.then));
|
|
267
266
|
if (!allowed)
|
|
268
267
|
throw new Error("Mode switch is not allowed. Allowed: " + JSON.stringify(selected?.switches ?? []));
|
|
269
|
-
|
|
270
|
-
if (object(input.entry) && input.entry.kind === "lesson" && object(input.entry.opening)) {
|
|
271
|
-
const { missionId, number } = input.entry.opening;
|
|
272
|
-
if (number !== undefined && (typeof number !== "number" || !Number.isSafeInteger(number)))
|
|
273
|
-
throw new Error("Lesson number must be an integer");
|
|
274
|
-
entry = await host.lessonEntry(text(missionId, "Mission id"), number);
|
|
275
|
-
}
|
|
276
|
-
else
|
|
277
|
-
entry = input.entry === undefined ? undefined : modeEntry(input.entry);
|
|
268
|
+
const entry = input.entry === undefined ? undefined : modeEntry(input.entry);
|
|
278
269
|
const to = { ...allowed, ...(entry === undefined ? {} : { entry }) };
|
|
279
270
|
await host.switchMode(session, to);
|
|
280
271
|
return { content: { status: "switching" }, switch: to };
|
package/dist/host.d.ts
CHANGED
|
@@ -107,8 +107,6 @@ export interface Host {
|
|
|
107
107
|
turn(session: HostSession, input: Readonly<{
|
|
108
108
|
learnerMessage?: string;
|
|
109
109
|
}>): Promise<HostChatSetup>;
|
|
110
|
-
/** After the conversation stops, end a completed Lesson and return its next surface. */
|
|
111
|
-
settle(session: HostSession): Promise<ModeSwitch | undefined>;
|
|
112
110
|
/** End admission immediately, leaving Theory judgments pending. */
|
|
113
111
|
end(session: HostSession): Promise<void>;
|
|
114
112
|
/** Finish pending Theory closes without holding up other Session operations. */
|
package/dist/inputs.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export declare function isMaterial(value: unknown): value is Material;
|
|
|
9
9
|
export declare function operations(value: unknown): readonly SemanticOperation[];
|
|
10
10
|
export declare function citations(value: unknown): readonly Citation[];
|
|
11
11
|
export declare function strings(value: unknown): readonly string[];
|
|
12
|
+
export declare const ENTRY_KINDS: ("mission" | "target" | "goal" | "review" | "checkpoint")[];
|
|
12
13
|
export declare function modeEntry(value: unknown): ModeEntry;
|
package/dist/inputs.js
CHANGED
|
@@ -173,6 +173,7 @@ export function strings(value) {
|
|
|
173
173
|
throw new Error("Expected strings");
|
|
174
174
|
return value;
|
|
175
175
|
}
|
|
176
|
+
export const ENTRY_KINDS = ["goal", "mission", "target", "review", "checkpoint"];
|
|
176
177
|
export function modeEntry(value) {
|
|
177
178
|
const input = record(value);
|
|
178
179
|
switch (input.kind) {
|
|
@@ -216,37 +217,6 @@ export function modeEntry(value) {
|
|
|
216
217
|
return { kind: "target", node: input.node };
|
|
217
218
|
case "review":
|
|
218
219
|
return { kind: "review", nodes: nodeIds(input.nodes) };
|
|
219
|
-
case "lesson": {
|
|
220
|
-
const lesson = record(input.lesson);
|
|
221
|
-
const mission = record(lesson.mission);
|
|
222
|
-
const section = record(lesson.section);
|
|
223
|
-
if (!nonempty(mission.id) ||
|
|
224
|
-
!nonempty(mission.statement) ||
|
|
225
|
-
!nonempty(lesson.name) ||
|
|
226
|
-
typeof lesson.number !== "number" ||
|
|
227
|
-
!Number.isSafeInteger(lesson.number) ||
|
|
228
|
-
typeof lesson.of !== "number" ||
|
|
229
|
-
!Number.isSafeInteger(lesson.of) ||
|
|
230
|
-
typeof section.number !== "number" ||
|
|
231
|
-
!isNodeId(section.milestone) ||
|
|
232
|
-
!nonempty(section.name))
|
|
233
|
-
throw new Error("Invalid Lesson snapshot");
|
|
234
|
-
return {
|
|
235
|
-
kind: "lesson",
|
|
236
|
-
lesson: {
|
|
237
|
-
mission: {
|
|
238
|
-
id: mission.id,
|
|
239
|
-
statement: mission.statement,
|
|
240
|
-
...(typeof mission.shortName === "string" ? { shortName: mission.shortName } : {}),
|
|
241
|
-
},
|
|
242
|
-
number: lesson.number,
|
|
243
|
-
of: lesson.of,
|
|
244
|
-
name: lesson.name,
|
|
245
|
-
nodes: nodeIds(lesson.nodes),
|
|
246
|
-
section: { number: section.number, milestone: section.milestone, name: section.name },
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
220
|
case "checkpoint":
|
|
251
221
|
if (!nonempty(input.missionId) || (input.milestone !== undefined && !isNodeId(input.milestone)))
|
|
252
222
|
throw new Error("Invalid checkpoint entry");
|
package/dist/learning.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { type LessonProgress, type LessonReading, type Mission, type ModeEntry, type NodeId, type PatchContent, type SessionMode, type Theory } from "@mmon-co/ncept-core";
|
|
2
2
|
import type { Host, HostChatSetup, HostConfig, HostSession, MissionReading, ModeSwitch, OpenHostOptions, SessionOpening, SessionIntent } from "./host.js";
|
|
3
3
|
import { Runtime, type LocalSession } from "./runtime.js";
|
|
4
|
-
|
|
4
|
+
type LearningView<S> = Awaited<ReturnType<Runtime<S>["snapshot"]>>;
|
|
5
|
+
/** Read current learning state without day processing, receipts or model calls. */
|
|
5
6
|
export declare function openLearningReader<S>(profileDir: string, theories: readonly Theory<S>[]): Promise<{
|
|
6
7
|
reading(): Promise<{
|
|
8
|
+
graph: import("@mmon-co/ncept-core").ResolvedGraph;
|
|
9
|
+
observations: readonly import("@mmon-co/ncept-core").Observation<unknown>[];
|
|
10
|
+
now: string;
|
|
7
11
|
missions: readonly MissionReading[];
|
|
8
12
|
nodes: {
|
|
9
13
|
id: `node-${string}`;
|
|
@@ -56,7 +60,6 @@ export declare class LearningHost<S> {
|
|
|
56
60
|
current(session: HostSession): Promise<LocalSession>;
|
|
57
61
|
mode(theory: Theory<S>, mode: string, entry?: ModeEntry): SessionMode<S> | undefined;
|
|
58
62
|
missionReadings(): Promise<readonly MissionReading[]>;
|
|
59
|
-
lessonEntry(missionId: string, number?: number): Promise<ModeEntry>;
|
|
60
63
|
reading(): Promise<{
|
|
61
64
|
missions: readonly MissionReading[];
|
|
62
65
|
dueReview: `node-${string}`[];
|
|
@@ -67,12 +70,11 @@ export declare class LearningHost<S> {
|
|
|
67
70
|
private endingRun;
|
|
68
71
|
end(session: HostSession): Promise<void>;
|
|
69
72
|
closePending(): Promise<void>;
|
|
70
|
-
settle(session: HostSession): Promise<ModeSwitch | undefined>;
|
|
71
73
|
retireMission(id: string, outcome: "achieved" | "abandoned"): Promise<void>;
|
|
72
74
|
begin(intent: SessionIntent): Promise<HostSession>;
|
|
73
75
|
open(input: SessionOpening): Promise<HostSession>;
|
|
74
76
|
switchMode(session: LocalSession, to: ModeSwitch): Promise<void>;
|
|
75
|
-
context(session: LocalSession): Promise<{
|
|
77
|
+
context(session: LocalSession, view?: LearningView<S>): Promise<{
|
|
76
78
|
missions: {
|
|
77
79
|
id: string;
|
|
78
80
|
statement: string;
|
|
@@ -92,13 +94,13 @@ export declare class LearningHost<S> {
|
|
|
92
94
|
};
|
|
93
95
|
}[];
|
|
94
96
|
lesson?: LessonProgress;
|
|
97
|
+
about: readonly NodeId[];
|
|
95
98
|
now: string;
|
|
96
99
|
graph: import("@mmon-co/ncept-core").ResolvedGraph;
|
|
97
100
|
state: S;
|
|
98
101
|
surface: import("@mmon-co/ncept-core").SurfaceId;
|
|
99
102
|
mode: string;
|
|
100
103
|
entry?: ModeEntry;
|
|
101
|
-
about: readonly NodeId[];
|
|
102
104
|
unscopedNodes?: readonly NodeId[];
|
|
103
105
|
tutorMessages?: readonly string[];
|
|
104
106
|
opening?: Readonly<{
|
|
@@ -118,3 +120,4 @@ export declare class LearningHost<S> {
|
|
|
118
120
|
start(): Promise<void>;
|
|
119
121
|
}
|
|
120
122
|
export declare function openHost<S>(options: OpenHostOptions<S>): Promise<Host>;
|
|
123
|
+
export {};
|
package/dist/learning.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isMission, isMissionRevision, isRunActiveChange, isRunPastEntry, isRunRetirement, nodeCascadedProperty, readMissionPath, readMissionRun, retire, selectGraph, setActive, tagIndex, } from "@mmon-co/ncept-core";
|
|
1
|
+
import { isMission, isMissionRevision, isRunActiveChange, isRunPastEntry, isRunRetirement, lessonHere, nodeCascadedProperty, readMissionPath, readMissionRun, retire, selectGraph, setActive, tagIndex, } from "@mmon-co/ncept-core";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { lock } from "proper-lockfile";
|
|
4
4
|
import { openProfile } from "./directory.js";
|
|
@@ -7,7 +7,7 @@ import { checkedTimezone, learnerDayAt } from "./days.js";
|
|
|
7
7
|
import { localPayload, localSettings, platform, Runtime, sessionStates, transcript, } from "./runtime.js";
|
|
8
8
|
import { hostTools } from "./host-tools.js";
|
|
9
9
|
import { mechanics } from "./mechanics.js";
|
|
10
|
-
import { isSurface, modeEntry } from "./inputs.js";
|
|
10
|
+
import { ENTRY_KINDS, isSurface, modeEntry } from "./inputs.js";
|
|
11
11
|
import { object, parsePiSession } from "./sessions.js";
|
|
12
12
|
import { reviewStop, sessionLength } from "./session-policy.js";
|
|
13
13
|
function readMissions(view, complete = false) {
|
|
@@ -47,7 +47,7 @@ function readMissions(view, complete = false) {
|
|
|
47
47
|
};
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
/** Read current learning state without day processing, receipts
|
|
50
|
+
/** Read current learning state without day processing, receipts or model calls. */
|
|
51
51
|
export async function openLearningReader(profileDir, theories) {
|
|
52
52
|
const profile = await openProfile(profileDir, theories, { readOnly: true });
|
|
53
53
|
const settings = localSettings(await profile.read());
|
|
@@ -65,6 +65,9 @@ export async function openLearningReader(profileDir, theories) {
|
|
|
65
65
|
const frontier = tagged("frontier");
|
|
66
66
|
const label = (id) => stringProperty(view.graph, id, "display:label", id);
|
|
67
67
|
return {
|
|
68
|
+
graph: view.graph,
|
|
69
|
+
observations: view.observations,
|
|
70
|
+
now: view.now,
|
|
68
71
|
missions: readMissions(view, true),
|
|
69
72
|
nodes: view.graph.nodes.map(({ id }) => ({
|
|
70
73
|
id,
|
|
@@ -84,6 +87,38 @@ export async function openLearningReader(profileDir, theories) {
|
|
|
84
87
|
},
|
|
85
88
|
};
|
|
86
89
|
}
|
|
90
|
+
function lessonAtEntry(session, graph, readings) {
|
|
91
|
+
const entry = session.entry;
|
|
92
|
+
const label = (id) => stringProperty(graph, id, "display:label", id);
|
|
93
|
+
if (entry?.kind === "target") {
|
|
94
|
+
const name = label(entry.node);
|
|
95
|
+
return {
|
|
96
|
+
mission: { id: entry.node, statement: name },
|
|
97
|
+
number: 1,
|
|
98
|
+
of: 1,
|
|
99
|
+
name,
|
|
100
|
+
section: { number: 1, milestone: entry.node, name },
|
|
101
|
+
nodes: [entry.node],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (entry?.kind !== "mission")
|
|
105
|
+
return;
|
|
106
|
+
const reading = readings.find(({ mission }) => mission.id === entry.id);
|
|
107
|
+
if (!reading?.path)
|
|
108
|
+
return;
|
|
109
|
+
const here = lessonHere(reading.path);
|
|
110
|
+
if (!here)
|
|
111
|
+
return;
|
|
112
|
+
const { lesson, section } = here;
|
|
113
|
+
return {
|
|
114
|
+
mission: { id: reading.mission.id, statement: reading.mission.statement },
|
|
115
|
+
number: lesson.number,
|
|
116
|
+
of: reading.path.lessonCount,
|
|
117
|
+
name: lesson.name ?? lesson.nodes.map(label).join(", "),
|
|
118
|
+
section: { number: section.number, milestone: section.milestone, name: label(section.milestone) },
|
|
119
|
+
nodes: lesson.nodes,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
87
122
|
function sessionTitle(session, profile, label) {
|
|
88
123
|
const entry = session.entry;
|
|
89
124
|
const mode = session.mode.charAt(0).toUpperCase() + session.mode.slice(1);
|
|
@@ -91,15 +126,13 @@ function sessionTitle(session, profile, label) {
|
|
|
91
126
|
if (entry?.kind === "review")
|
|
92
127
|
title = "Review · " + entry.nodes.length + " due";
|
|
93
128
|
else {
|
|
94
|
-
const name = entry?.kind === "
|
|
95
|
-
? entry.
|
|
96
|
-
: entry?.kind === "
|
|
97
|
-
?
|
|
98
|
-
: entry?.kind === "
|
|
99
|
-
?
|
|
100
|
-
:
|
|
101
|
-
? entry.text
|
|
102
|
-
: undefined;
|
|
129
|
+
const name = entry?.kind === "mission"
|
|
130
|
+
? missions(profile).find((mission) => mission.id === entry.id)?.statement
|
|
131
|
+
: entry?.kind === "target"
|
|
132
|
+
? label(entry.node)
|
|
133
|
+
: entry?.kind === "goal"
|
|
134
|
+
? entry.text
|
|
135
|
+
: undefined;
|
|
103
136
|
if (name)
|
|
104
137
|
title += " · " + name;
|
|
105
138
|
}
|
|
@@ -224,51 +257,10 @@ export class LearningHost {
|
|
|
224
257
|
async missionReadings() {
|
|
225
258
|
return readMissions(await this.runtime.snapshot());
|
|
226
259
|
}
|
|
227
|
-
async lessonEntry(missionId, number) {
|
|
228
|
-
const view = await this.runtime.snapshot();
|
|
229
|
-
const reading = (await this.missionReadings()).find(({ mission }) => mission.id === missionId);
|
|
230
|
-
if (!reading)
|
|
231
|
-
throw new Error("Unknown Mission");
|
|
232
|
-
const context = {
|
|
233
|
-
graph: view.graph,
|
|
234
|
-
projection: view.theory.project(view.graph, view.state),
|
|
235
|
-
observations: view.observations,
|
|
236
|
-
activities: [],
|
|
237
|
-
};
|
|
238
|
-
const future = view.theory.path?.({
|
|
239
|
-
...context,
|
|
240
|
-
targets: reading.mission.targets.map(({ node }) => node),
|
|
241
|
-
past: reading.run.past,
|
|
242
|
-
now: view.now,
|
|
243
|
-
minutes: sessionLength(localSettings(view.profile)),
|
|
244
|
-
});
|
|
245
|
-
if (!future)
|
|
246
|
-
throw new Error("Theory provides no Mission path");
|
|
247
|
-
const path = readMissionPath(future, view.theory, context);
|
|
248
|
-
const section = path.sections.find(({ lessons }) => lessons.some((lesson) => lesson.kind === "lesson" && (number === undefined ? !lesson.cleared : lesson.number === number)));
|
|
249
|
-
const lesson = section?.lessons.find((lesson) => lesson.kind === "lesson" && (number === undefined ? !lesson.cleared : lesson.number === number));
|
|
250
|
-
if (!section || !lesson)
|
|
251
|
-
throw new Error("No matching Lesson in this Mission");
|
|
252
|
-
return {
|
|
253
|
-
kind: "lesson",
|
|
254
|
-
lesson: {
|
|
255
|
-
mission: { id: reading.mission.id, statement: reading.mission.statement },
|
|
256
|
-
number: lesson.number,
|
|
257
|
-
of: path.lessonCount,
|
|
258
|
-
name: lesson.name ?? lesson.nodes.map((id) => stringProperty(view.graph, id, "display:label", id)).join(", "),
|
|
259
|
-
section: {
|
|
260
|
-
number: section.number,
|
|
261
|
-
milestone: section.milestone,
|
|
262
|
-
name: stringProperty(view.graph, section.milestone, "display:label", section.milestone),
|
|
263
|
-
},
|
|
264
|
-
nodes: lesson.nodes,
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
260
|
async reading() {
|
|
269
261
|
const view = await this.runtime.snapshot();
|
|
270
262
|
return {
|
|
271
|
-
missions:
|
|
263
|
+
missions: readMissions(view),
|
|
272
264
|
dueReview: [...tagIndex(view.theory.project(view.graph, view.state))("review:due")],
|
|
273
265
|
};
|
|
274
266
|
}
|
|
@@ -383,20 +375,6 @@ export class LearningHost {
|
|
|
383
375
|
if (failures.length)
|
|
384
376
|
throw new AggregateError(failures, "Session close failed");
|
|
385
377
|
}
|
|
386
|
-
async settle(session) {
|
|
387
|
-
const current = await this.current(session);
|
|
388
|
-
if (current.closed || current.closing || current.mode !== "lesson" || current.entry?.kind !== "lesson")
|
|
389
|
-
return;
|
|
390
|
-
if (!(await this.context(current)).lesson?.complete)
|
|
391
|
-
return;
|
|
392
|
-
await this.end(current);
|
|
393
|
-
return {
|
|
394
|
-
mode: "charting",
|
|
395
|
-
then: "next",
|
|
396
|
-
carry: { kind: "brief" },
|
|
397
|
-
entry: { kind: "mission", id: current.entry.lesson.mission.id },
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
378
|
async retireMission(id, outcome) {
|
|
401
379
|
const view = await this.runtime.snapshot();
|
|
402
380
|
if (!missions(view.profile).some((mission) => mission.id === id))
|
|
@@ -431,7 +409,8 @@ export class LearningHost {
|
|
|
431
409
|
const reading = (await this.missionReadings()).find(({ mission }) => mission.id === intent.missionId);
|
|
432
410
|
if (!reading || reading.run.retired?.outcome === "abandoned")
|
|
433
411
|
throw new Error("Mission is not available");
|
|
434
|
-
const { mission, run, next } = reading;
|
|
412
|
+
const { mission, run, next, path } = reading;
|
|
413
|
+
const entry = { kind: "mission", id: mission.id };
|
|
435
414
|
if (intent.kind === "continue" && run.active)
|
|
436
415
|
return this.open({ mode: "empty", resume: run.active });
|
|
437
416
|
if (run.retired && intent.kind !== "continue")
|
|
@@ -443,9 +422,9 @@ export class LearningHost {
|
|
|
443
422
|
if (intent.kind === "revise-lesson") {
|
|
444
423
|
const view = await this.runtime.snapshot();
|
|
445
424
|
const active = sessionStates(view.profile).find(({ id }) => id === run.active);
|
|
446
|
-
if (active?.entry?.kind !== "
|
|
425
|
+
if (active?.mode !== "lesson" || active.entry?.kind !== "mission" || !path || !lessonHere(path))
|
|
447
426
|
throw new Error("There is no active Lesson to revise");
|
|
448
|
-
return this.open({ mode: "lesson", entry
|
|
427
|
+
return this.open({ mode: "lesson", entry });
|
|
449
428
|
}
|
|
450
429
|
if (intent.kind === "tell-tutor" || intent.kind === "revise-route" || !mission.targets.length)
|
|
451
430
|
return this.open({ mode: "charting", entry: { kind: "mission", id: mission.id } });
|
|
@@ -458,7 +437,7 @@ export class LearningHost {
|
|
|
458
437
|
throw new Error("This Mission has no following stop; revise the route or finish it");
|
|
459
438
|
if (stop.checkpoint)
|
|
460
439
|
return this.open({ mode: "charting", entry: { kind: "mission", id: mission.id } });
|
|
461
|
-
return this.open({ mode: "lesson", entry
|
|
440
|
+
return this.open({ mode: "lesson", entry });
|
|
462
441
|
}
|
|
463
442
|
async open(input) {
|
|
464
443
|
const skipMission = input.skip?.mission;
|
|
@@ -471,50 +450,25 @@ export class LearningHost {
|
|
|
471
450
|
throw new Error("Unknown Mission");
|
|
472
451
|
if (reading.run.retired)
|
|
473
452
|
throw new Error("A finished Mission can only continue or resume a Session");
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
graph: view.graph,
|
|
477
|
-
projection: view.theory.project(view.graph, view.state),
|
|
478
|
-
observations: view.observations,
|
|
479
|
-
activities: [],
|
|
480
|
-
};
|
|
481
|
-
const future = view.theory.path?.({
|
|
482
|
-
...context,
|
|
483
|
-
targets: reading.mission.targets.map(({ node }) => node),
|
|
484
|
-
past: reading.run.past,
|
|
485
|
-
now: view.now,
|
|
486
|
-
minutes: sessionLength(localSettings(view.profile)),
|
|
487
|
-
});
|
|
488
|
-
if (!future)
|
|
453
|
+
const path = reading.path;
|
|
454
|
+
if (!path)
|
|
489
455
|
throw new Error("Theory provides no Mission path");
|
|
490
|
-
const stops =
|
|
491
|
-
const
|
|
492
|
-
const
|
|
493
|
-
const activeIndex = frozenStop
|
|
494
|
-
? stops.findIndex((stop) => stop.kind === frozenStop.kind &&
|
|
495
|
-
stop.nodes.length === frozenStop.nodes?.length &&
|
|
496
|
-
stop.nodes.every((node) => frozenStop.nodes?.includes(node)))
|
|
497
|
-
: -1;
|
|
498
|
-
const now = activeIndex >= 0 ? activeIndex : stops.findIndex((stop) => !stop.cleared);
|
|
456
|
+
const stops = path.sections.flatMap(({ lessons }) => lessons);
|
|
457
|
+
const here = lessonHere(path)?.lesson;
|
|
458
|
+
const now = here ? stops.indexOf(here) : -1;
|
|
499
459
|
const skip = input.skip;
|
|
500
460
|
const index = skip.kind === "skip-lesson"
|
|
501
|
-
? now
|
|
461
|
+
? stops.findIndex((stop, position) => position > now && !stop.cleared)
|
|
502
462
|
: stops.findIndex((stop) => stop.kind === skip.stop.kind &&
|
|
503
463
|
stop.number === skip.stop.number &&
|
|
504
464
|
stop.checkpoint?.milestone === skip.stop.checkpoint?.milestone);
|
|
505
465
|
if (index < 0 || !stops[index])
|
|
506
466
|
throw new Error("This Mission has no following stop; revise the route or finish it");
|
|
507
|
-
if (
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
skipped = stops.slice(now, index);
|
|
511
|
-
}
|
|
467
|
+
if (now < 0 || index <= now || stops[index].cleared)
|
|
468
|
+
throw new Error("Choose an uncleared stop after the current Lesson");
|
|
469
|
+
skipped = stops.slice(now, index).filter((stop) => stop.numbered && !stop.cleared && !stop.checkpoint);
|
|
512
470
|
const stop = stops[index];
|
|
513
|
-
const entry = stop.kind === "review"
|
|
514
|
-
? { kind: "review", nodes: stop.nodes }
|
|
515
|
-
: stop.checkpoint
|
|
516
|
-
? { kind: "mission", id: reading.mission.id }
|
|
517
|
-
: await this.lessonEntry(reading.mission.id, stop.number);
|
|
471
|
+
const entry = stop.kind === "review" ? { kind: "review", nodes: stop.nodes } : { kind: "mission", id: reading.mission.id };
|
|
518
472
|
input = { mode: stop.checkpoint ? "charting" : "lesson", entry };
|
|
519
473
|
}
|
|
520
474
|
const view = await this.runtime.snapshot();
|
|
@@ -530,15 +484,13 @@ export class LearningHost {
|
|
|
530
484
|
mode: input.mode,
|
|
531
485
|
about: input.entry?.kind === "review"
|
|
532
486
|
? input.entry.nodes
|
|
533
|
-
: input.entry?.kind === "
|
|
534
|
-
? input.entry.
|
|
535
|
-
:
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
.flatMap((observation) => observation.nodes ?? observation.about ?? [])),
|
|
541
|
-
],
|
|
487
|
+
: input.entry?.kind === "target"
|
|
488
|
+
? [input.entry.node]
|
|
489
|
+
: [
|
|
490
|
+
...new Set(view.observations
|
|
491
|
+
.filter((observation) => observation.surface === surface)
|
|
492
|
+
.flatMap((observation) => observation.nodes ?? observation.about ?? [])),
|
|
493
|
+
],
|
|
542
494
|
closed: true,
|
|
543
495
|
...(input.entry === undefined ? {} : { entry: input.entry }),
|
|
544
496
|
};
|
|
@@ -559,24 +511,20 @@ export class LearningHost {
|
|
|
559
511
|
const missionId = resumed?.mission ??
|
|
560
512
|
(entry?.kind === "mission"
|
|
561
513
|
? entry.id
|
|
562
|
-
: entry?.kind === "
|
|
563
|
-
? entry.
|
|
564
|
-
:
|
|
565
|
-
? entry.missionId
|
|
566
|
-
: (input.mission ?? skipMission ?? pending?.from.mission));
|
|
514
|
+
: entry?.kind === "checkpoint"
|
|
515
|
+
? entry.missionId
|
|
516
|
+
: (input.mission ?? skipMission ?? pending?.from.mission));
|
|
567
517
|
const mission = missionId ? missions(view.profile).find(({ id }) => id === missionId) : undefined;
|
|
568
518
|
if (missionId && !mission)
|
|
569
519
|
throw new Error("Unknown Mission");
|
|
570
|
-
const about = resumed?.about ??
|
|
520
|
+
const about = (mode === "lesson" && entry?.kind === "mission" ? undefined : resumed?.about) ??
|
|
571
521
|
(entry?.kind === "target"
|
|
572
522
|
? [entry.node]
|
|
573
523
|
: entry?.kind === "review"
|
|
574
524
|
? entry.nodes
|
|
575
|
-
:
|
|
576
|
-
?
|
|
577
|
-
:
|
|
578
|
-
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
579
|
-
: []);
|
|
525
|
+
: mission
|
|
526
|
+
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
527
|
+
: []);
|
|
580
528
|
for (const node of about)
|
|
581
529
|
if (!view.graph.nodes.some(({ id }) => id === node))
|
|
582
530
|
throw new Error("Missing Node " + node);
|
|
@@ -598,16 +546,11 @@ export class LearningHost {
|
|
|
598
546
|
const entries = [];
|
|
599
547
|
if (missionId) {
|
|
600
548
|
const before = missionRun(view.profile, missionId);
|
|
601
|
-
const stop = {
|
|
602
|
-
kind: entry?.kind ?? mode,
|
|
603
|
-
name: entry?.kind === "lesson" ? entry.lesson.name : mode,
|
|
604
|
-
nodes: about,
|
|
605
|
-
};
|
|
606
549
|
const target = resumed && before.past.some((entry) => entry.kind === "session" && entry.session === id)
|
|
607
550
|
? { kind: "resume", session: id }
|
|
608
551
|
: pending?.to.then === "aside"
|
|
609
552
|
? { kind: "aside", session: id }
|
|
610
|
-
: { kind: "
|
|
553
|
+
: { kind: "attach", session: id };
|
|
611
554
|
// A fresh front end adopting an open aside keeps it beside its parent.
|
|
612
555
|
const result = resumed?.parent === before.active && !resumed.closed
|
|
613
556
|
? { run: before, close: [] }
|
|
@@ -663,25 +606,21 @@ export class LearningHost {
|
|
|
663
606
|
throw new Error("This mode does not allow that switch");
|
|
664
607
|
this.mode(view.theory, to.mode, to.entry);
|
|
665
608
|
if (to.then === "here") {
|
|
666
|
-
const missionId = to.entry?.kind === "
|
|
667
|
-
? to.entry.
|
|
668
|
-
: to.entry?.kind === "
|
|
669
|
-
? to.entry.
|
|
670
|
-
:
|
|
671
|
-
? to.entry.missionId
|
|
672
|
-
: session.mission;
|
|
609
|
+
const missionId = to.entry?.kind === "mission"
|
|
610
|
+
? to.entry.id
|
|
611
|
+
: to.entry?.kind === "checkpoint"
|
|
612
|
+
? to.entry.missionId
|
|
613
|
+
: session.mission;
|
|
673
614
|
const mission = missions(view.profile).find(({ id }) => id === missionId);
|
|
674
615
|
if (missionId && !mission)
|
|
675
616
|
throw new Error("Unknown Mission");
|
|
676
617
|
const about = to.entry?.kind === "review"
|
|
677
618
|
? to.entry.nodes
|
|
678
|
-
: to.entry?.kind === "
|
|
679
|
-
? to.entry.
|
|
680
|
-
:
|
|
681
|
-
?
|
|
682
|
-
:
|
|
683
|
-
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
684
|
-
: session.about;
|
|
619
|
+
: to.entry?.kind === "target"
|
|
620
|
+
? [to.entry.node]
|
|
621
|
+
: mission
|
|
622
|
+
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
623
|
+
: session.about;
|
|
685
624
|
for (const node of about)
|
|
686
625
|
if (!view.graph.nodes.some(({ id }) => id === node))
|
|
687
626
|
throw new Error("Missing Node " + node);
|
|
@@ -710,16 +649,16 @@ export class LearningHost {
|
|
|
710
649
|
else
|
|
711
650
|
this.pendingSwitch = { from: session, to };
|
|
712
651
|
}
|
|
713
|
-
async context(session) {
|
|
714
|
-
|
|
715
|
-
const ctx = await this.runtime.context(session);
|
|
716
|
-
const readings =
|
|
652
|
+
async context(session, view) {
|
|
653
|
+
view ??= await this.runtime.snapshot();
|
|
654
|
+
const ctx = await this.runtime.context(session, view);
|
|
655
|
+
const readings = readMissions(view);
|
|
656
|
+
const here = session.mode === "lesson" ? lessonAtEntry(session, ctx.graph, readings) : undefined;
|
|
717
657
|
let lesson;
|
|
718
|
-
if (
|
|
719
|
-
const snapshot = session.entry.lesson;
|
|
658
|
+
if (here) {
|
|
720
659
|
const projection = view.theory.project(ctx.graph, ctx.state);
|
|
721
|
-
const progress = view.theory.progress(ctx.graph, projection,
|
|
722
|
-
const nodes =
|
|
660
|
+
const progress = view.theory.progress(ctx.graph, projection, here.nodes);
|
|
661
|
+
const nodes = here.nodes.map((id) => ({
|
|
723
662
|
id,
|
|
724
663
|
label: stringProperty(ctx.graph, id, "display:label", id),
|
|
725
664
|
criterion: stringProperty(ctx.graph, id, "pedagogy:criterion", ""),
|
|
@@ -732,11 +671,11 @@ export class LearningHost {
|
|
|
732
671
|
projection,
|
|
733
672
|
observations: view.observations,
|
|
734
673
|
activities: [],
|
|
735
|
-
}, [{ kind: "lesson", nodes:
|
|
674
|
+
}, [{ kind: "lesson", nodes: here.nodes, numbered: true }]);
|
|
736
675
|
lesson = {
|
|
737
|
-
|
|
676
|
+
here,
|
|
738
677
|
nodes,
|
|
739
|
-
edges: ctx.graph.edges.filter(({ from, to }) =>
|
|
678
|
+
edges: ctx.graph.edges.filter(({ from, to }) => here.nodes.includes(from) && here.nodes.includes(to)),
|
|
740
679
|
alsoShown: [],
|
|
741
680
|
doneCount: nodes.filter(({ status }) => status === "done").length,
|
|
742
681
|
complete: nodes.every(({ status }) => status === "done"),
|
|
@@ -746,7 +685,7 @@ export class LearningHost {
|
|
|
746
685
|
}
|
|
747
686
|
return {
|
|
748
687
|
...ctx,
|
|
749
|
-
...(lesson ? { lesson } : {}),
|
|
688
|
+
...(lesson ? { lesson, about: lesson.here.nodes } : {}),
|
|
750
689
|
missions: readings.map(({ mission, run, next }) => ({
|
|
751
690
|
id: mission.id,
|
|
752
691
|
statement: mission.statement,
|
|
@@ -764,11 +703,11 @@ export class LearningHost {
|
|
|
764
703
|
if (session.closed || session.closing)
|
|
765
704
|
throw new Error("Session is ended; resume it first");
|
|
766
705
|
let view = await this.runtime.snapshot();
|
|
767
|
-
let ctx = await this.context(session);
|
|
706
|
+
let ctx = await this.context(session, view);
|
|
768
707
|
if (learnerMessage !== undefined && view.theory.chat?.reply) {
|
|
769
708
|
await this.runtime.execute(view.theory.chat.reply(ctx, learnerMessage), session);
|
|
770
709
|
view = await this.runtime.snapshot();
|
|
771
|
-
ctx = await this.context(session);
|
|
710
|
+
ctx = await this.context(session, view);
|
|
772
711
|
}
|
|
773
712
|
if (learnerMessage === undefined && transcript(view.profile, session.surface).turns.length === 0) {
|
|
774
713
|
const latest = sessionStates(view.profile)
|
|
@@ -814,7 +753,10 @@ export class LearningHost {
|
|
|
814
753
|
mode: session.mode,
|
|
815
754
|
capabilities,
|
|
816
755
|
switches: selected?.switches ?? [],
|
|
817
|
-
entries: Object.fromEntries(Object.entries(view.theory.modes ?? {}).map(([name,
|
|
756
|
+
entries: Object.fromEntries(Object.entries(view.theory.modes ?? {}).map(([name, { entry }]) => [
|
|
757
|
+
name,
|
|
758
|
+
{ ...entry, kinds: ENTRY_KINDS.filter((kind) => entry.kinds.includes(kind)) },
|
|
759
|
+
])),
|
|
818
760
|
}),
|
|
819
761
|
]
|
|
820
762
|
.filter(Boolean)
|
|
@@ -873,7 +815,6 @@ export async function openHost(options) {
|
|
|
873
815
|
open: (input) => learning.serial(() => learning.open(input)),
|
|
874
816
|
begin: (intent) => learning.serial(() => learning.begin(intent)),
|
|
875
817
|
turn: (session, input) => learning.serial(() => learning.turn(session, input.learnerMessage)),
|
|
876
|
-
settle: (session) => learning.serial(() => learning.settle(session)),
|
|
877
818
|
end: (session) => learning.serial(() => learning.end(session)),
|
|
878
819
|
closePending: () => learning.closePending(),
|
|
879
820
|
close: async (session) => {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare class Runtime<S> {
|
|
|
41
41
|
value: void;
|
|
42
42
|
entries: Observation<unknown>[];
|
|
43
43
|
}>;
|
|
44
|
-
context(session: LocalSession): Promise<ChatContext<S>>;
|
|
44
|
+
context(session: LocalSession, view?: Awaited<ReturnType<Runtime<S>["snapshot"]>>): Promise<ChatContext<S>>;
|
|
45
45
|
prospective(content: PatchContent): Promise<{
|
|
46
46
|
profile: {
|
|
47
47
|
patches: import("@mmon-co/ncept-core").ClosedPatchBundle;
|
package/dist/runtime.js
CHANGED
|
@@ -288,8 +288,8 @@ export class Runtime {
|
|
|
288
288
|
}
|
|
289
289
|
return this.prepare(view.theory.event(event, view), session, view);
|
|
290
290
|
}
|
|
291
|
-
async context(session) {
|
|
292
|
-
|
|
291
|
+
async context(session, view) {
|
|
292
|
+
view ??= await this.snapshot();
|
|
293
293
|
return {
|
|
294
294
|
...view,
|
|
295
295
|
surface: session.surface,
|