@mmon-co/ncept-local 0.3.10 → 0.3.12
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/host.d.ts +9 -2
- package/dist/hub.d.ts +2 -2
- package/dist/hub.js +53 -66
- package/dist/learning.d.ts +2 -0
- package/dist/learning.js +106 -39
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +2 -1
- package/package.json +3 -3
package/dist/host.d.ts
CHANGED
|
@@ -39,11 +39,17 @@ export interface HostSession {
|
|
|
39
39
|
readonly mode: string;
|
|
40
40
|
readonly entry?: ModeEntry;
|
|
41
41
|
}
|
|
42
|
+
export type DueCheckIn = Readonly<{
|
|
43
|
+
milestone?: NodeId;
|
|
44
|
+
required: boolean;
|
|
45
|
+
final?: true;
|
|
46
|
+
}>;
|
|
42
47
|
export interface MissionReading {
|
|
43
48
|
readonly mission: Mission;
|
|
44
49
|
readonly run: MissionRunReading;
|
|
45
50
|
readonly next: readonly LessonReading[];
|
|
46
51
|
readonly path?: MissionPathReading;
|
|
52
|
+
readonly checkIn?: DueCheckIn;
|
|
47
53
|
}
|
|
48
54
|
export interface HostReading {
|
|
49
55
|
readonly missions: readonly MissionReading[];
|
|
@@ -78,7 +84,7 @@ export type SessionOpening = Readonly<{
|
|
|
78
84
|
} | {
|
|
79
85
|
mission: string;
|
|
80
86
|
kind: "skip-to";
|
|
81
|
-
stop: Pick<LessonReading, "kind" | "number"
|
|
87
|
+
stop: Pick<LessonReading, "kind" | "number">;
|
|
82
88
|
};
|
|
83
89
|
}>;
|
|
84
90
|
/** Learner entry controls; resolved against current Profile state by its writing tutor. */
|
|
@@ -88,7 +94,7 @@ export type SessionIntent = Readonly<{
|
|
|
88
94
|
}> | Readonly<{
|
|
89
95
|
kind: "skip-to";
|
|
90
96
|
missionId: string;
|
|
91
|
-
stop: Pick<LessonReading, "kind" | "number"
|
|
97
|
+
stop: Pick<LessonReading, "kind" | "number">;
|
|
92
98
|
}> | Readonly<{
|
|
93
99
|
kind: "continue" | "revise-lesson" | "revise-route";
|
|
94
100
|
missionId: string;
|
|
@@ -128,6 +134,7 @@ export interface Host {
|
|
|
128
134
|
version: string;
|
|
129
135
|
title: string;
|
|
130
136
|
description?: string;
|
|
137
|
+
missions?: readonly string[];
|
|
131
138
|
}>): Promise<HubRelease>;
|
|
132
139
|
/**
|
|
133
140
|
* Publish one Mission's map (its targets and their prerequisites) as a new Hub release and
|
package/dist/hub.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClosedPatchBundle, type Mission } from "@mmon-co/ncept-core";
|
|
1
|
+
import { type ClosedPatchBundle, type Mission, type ReifiedMissionOrigin } from "@mmon-co/ncept-core";
|
|
2
2
|
import { type ProfileDirectory } from "./directory.js";
|
|
3
3
|
import { type ConfiguredTheory } from "./exchange.js";
|
|
4
4
|
import type { Confirm, Host, HubOptions } from "./host.js";
|
|
@@ -7,7 +7,7 @@ import type { Confirm, Host, HubOptions } from "./host.js";
|
|
|
7
7
|
* the release carries that map alone whatever Patches it was learnt from, and offering the
|
|
8
8
|
* Mission to whoever opens it.
|
|
9
9
|
*/
|
|
10
|
-
export declare function missionBundle(patches: ClosedPatchBundle, mission: Mission, title: string): {
|
|
10
|
+
export declare function missionBundle(patches: ClosedPatchBundle, mission: Mission, title: string, origin?: ReifiedMissionOrigin): {
|
|
11
11
|
bundle: ClosedPatchBundle;
|
|
12
12
|
skills: number;
|
|
13
13
|
};
|
package/dist/hub.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdtemp, rename, rm } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, basename, join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import metadata from "../package.json" with { type: "json" };
|
|
5
|
-
import { attachmentDigest,
|
|
5
|
+
import { attachmentDigest, bundleForRevision, candidateRevision, exactPatchRefKey, isAttachment, isContentDigest, isMissionRevision, latestMissionRevision, isPatchId, migrateTheoryPatchClosure, notebookSelection, PATCH_MISSIONS_PROPERTY, readReifiedMissions, reifyProfileMissions, relocateGuidance, reifyView, releasePrecedenceKey, resolveTheory, resolvePatchBundle, revisionContent, sameExactPatchRef, selectGraph, withReifiedMissions, } from "@mmon-co/ncept-core";
|
|
6
6
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
7
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
8
8
|
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
@@ -15,7 +15,7 @@ import { validate, unpack } from "./exchange.js";
|
|
|
15
15
|
* the release carries that map alone whatever Patches it was learnt from, and offering the
|
|
16
16
|
* Mission to whoever opens it.
|
|
17
17
|
*/
|
|
18
|
-
export function missionBundle(patches, mission, title) {
|
|
18
|
+
export function missionBundle(patches, mission, title, origin) {
|
|
19
19
|
const graph = resolvePatchBundle(patches, new Set(["local"]), notebookSelection(patches));
|
|
20
20
|
const cone = selectGraph(graph, { cone: { targets: mission.targets.map(({ node }) => node) } });
|
|
21
21
|
if (!cone.nodes.length)
|
|
@@ -27,17 +27,8 @@ export function missionBundle(patches, mission, title) {
|
|
|
27
27
|
const provenance = reified.metadata.citations.find((citation) => citation.kind === "reified_from");
|
|
28
28
|
const mapped = new Map(provenance?.kind === "reified_from" ? provenance.entities.nodes.map(({ source, target }) => [source, target]) : []);
|
|
29
29
|
const node = (id) => mapped.get(id) ?? id;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
...(entry.nodes ? { nodes: entry.nodes.map(node) } : {}),
|
|
33
|
-
...(entry.mode === "append"
|
|
34
|
-
? {}
|
|
35
|
-
: "replace" in entry.mode
|
|
36
|
-
? { mode: { replace: entry.mode.replace.map((ref) => ("name" in ref ? ref : { node: node(ref.node) })) } }
|
|
37
|
-
: { mode: { keep: entry.mode.keep.map((ref) => ("name" in ref ? ref : { node: node(ref.node) })) } }),
|
|
38
|
-
}));
|
|
39
|
-
const guidance = entries(mission.guidance);
|
|
40
|
-
const assessment = entries(mission.assessment);
|
|
30
|
+
const guidance = mission.guidance && relocateGuidance(mission.guidance, node);
|
|
31
|
+
const assessment = mission.assessment && relocateGuidance(mission.assessment, node);
|
|
41
32
|
// The Hub offers this to whoever opens the link as a Mission they can start.
|
|
42
33
|
const suggestion = {
|
|
43
34
|
id: randomUUID(),
|
|
@@ -47,54 +38,21 @@ export function missionBundle(patches, mission, title) {
|
|
|
47
38
|
targetNodes: mission.targets.map((target) => node(target.node)),
|
|
48
39
|
...(guidance?.length ? { guidance } : {}),
|
|
49
40
|
...(assessment?.length ? { assessment } : {}),
|
|
41
|
+
...(origin === undefined ? {} : { origin }),
|
|
50
42
|
};
|
|
51
43
|
const content = {
|
|
52
44
|
...reified,
|
|
53
|
-
metadata: {
|
|
54
|
-
|
|
45
|
+
metadata: withReifiedMissions({
|
|
46
|
+
...reified.metadata,
|
|
47
|
+
// The Hub records graph provenance itself and refuses it from a client.
|
|
55
48
|
citations: reified.metadata.citations.filter((citation) => citation.kind !== "reified_from"),
|
|
56
|
-
|
|
57
|
-
},
|
|
49
|
+
}, [suggestion]),
|
|
58
50
|
};
|
|
59
51
|
const revision = candidateRevision(`patch-${randomUUID()}`, content);
|
|
60
52
|
const bundle = bundleForRevision(revision.ref, new Map([[revision.ref.digest, content]]));
|
|
61
53
|
resolvePatchBundle(bundle);
|
|
62
54
|
return { bundle, skills: cone.nodes.length };
|
|
63
55
|
}
|
|
64
|
-
/** The Application's metadata property for Missions a release offers its readers. */
|
|
65
|
-
const MISSION_SUGGESTIONS = "application:mission-suggestions";
|
|
66
|
-
function suggestedMissions(revision, contents) {
|
|
67
|
-
const encoded = revision.metadata.properties[MISSION_SUGGESTIONS];
|
|
68
|
-
if (encoded === undefined)
|
|
69
|
-
return [];
|
|
70
|
-
if (typeof encoded !== "string")
|
|
71
|
-
throw new Error("Invalid Mission suggestions metadata");
|
|
72
|
-
const suggestions = JSON.parse(encoded);
|
|
73
|
-
if (!Array.isArray(suggestions))
|
|
74
|
-
throw new Error("Invalid Mission suggestions metadata");
|
|
75
|
-
const nodes = new Set(resolvePatchBundle(bundleForRevision(revision.ref, contents)).nodes.map(({ id }) => id));
|
|
76
|
-
const ids = new Set();
|
|
77
|
-
return suggestions.map((item) => {
|
|
78
|
-
if (!object(item) || typeof item.id !== "string" || !item.id || !Array.isArray(item.targetNodes))
|
|
79
|
-
throw new Error("Invalid Mission suggestion");
|
|
80
|
-
const { statement, targetNodes, guidance, assessment, preselected } = item;
|
|
81
|
-
const mission = {
|
|
82
|
-
id: "hub-" + contentDigest([revision.ref.identity, item.id]),
|
|
83
|
-
statement,
|
|
84
|
-
priority: 1,
|
|
85
|
-
targets: targetNodes.map((node) => ({ node, provenance: revision.ref })),
|
|
86
|
-
...(guidance === undefined ? {} : { guidance }),
|
|
87
|
-
...(assessment === undefined ? {} : { assessment }),
|
|
88
|
-
};
|
|
89
|
-
if (!isMission(mission) ||
|
|
90
|
-
ids.has(mission.id) ||
|
|
91
|
-
new Set(targetNodes).size !== targetNodes.length ||
|
|
92
|
-
mission.targets.some(({ node }) => !nodes.has(node)))
|
|
93
|
-
throw new Error("Invalid Mission suggestion");
|
|
94
|
-
ids.add(mission.id);
|
|
95
|
-
return { mission, preselected: preselected === true };
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
56
|
function releaseAddress(value, base) {
|
|
99
57
|
const page = value.match(/^(https?:\/\/.+)\/hub\/([^/]+)\/releases\/([^/?#]+)(?:[?#].*)?$/);
|
|
100
58
|
const api = value.match(/^(https?:\/\/.+)\/hub\/v1\/releases\/([^/]+)\/([^/?#]+)(?:[?#].*)?$/);
|
|
@@ -294,20 +252,40 @@ export function connectHub(profile, theories, confirm, createMission, options =
|
|
|
294
252
|
const next = candidateRevision(personal.ref.identity, content);
|
|
295
253
|
contents.set(next.ref.digest, content);
|
|
296
254
|
resolvePatchBundle(bundleForRevision(next.ref, contents));
|
|
297
|
-
const suggestions =
|
|
298
|
-
const existing = new Set(
|
|
255
|
+
const suggestions = readReifiedMissions(revisionContent(adopted), resolvePatchBundle(bundleForRevision(adopted.ref, contents)));
|
|
256
|
+
const existing = new Set();
|
|
257
|
+
for (const entry of current.log) {
|
|
258
|
+
if (!isMissionRevision(entry))
|
|
259
|
+
continue;
|
|
260
|
+
const source = entry.mission.source;
|
|
261
|
+
if (source?.patch.identity === adopted.ref.identity)
|
|
262
|
+
existing.add(source.suggestionId);
|
|
263
|
+
}
|
|
299
264
|
const selectedMissions = [];
|
|
300
|
-
for (const
|
|
301
|
-
if (existing.has(
|
|
265
|
+
for (const item of suggestions) {
|
|
266
|
+
if (existing.has(item.id))
|
|
302
267
|
continue;
|
|
303
268
|
if (await confirm({
|
|
304
269
|
kind: "hub.pull.mission",
|
|
305
270
|
title: "Add the suggested Mission?",
|
|
306
|
-
description:
|
|
307
|
-
detail: { statement:
|
|
308
|
-
defaultAccepted: preselected,
|
|
271
|
+
description: item.statement,
|
|
272
|
+
detail: { statement: item.statement },
|
|
273
|
+
defaultAccepted: item.preselected === true,
|
|
309
274
|
}))
|
|
310
|
-
selectedMissions.push(
|
|
275
|
+
selectedMissions.push({
|
|
276
|
+
id: `mission-${randomUUID()}`,
|
|
277
|
+
statement: item.statement,
|
|
278
|
+
priority: 1,
|
|
279
|
+
targets: item.targetNodes.map((node) => ({ node, provenance: adopted.ref })),
|
|
280
|
+
...(item.guidance === undefined ? {} : { guidance: item.guidance }),
|
|
281
|
+
...(item.assessment === undefined ? {} : { assessment: item.assessment }),
|
|
282
|
+
source: {
|
|
283
|
+
patch: bundle.terminal,
|
|
284
|
+
version: selected.version,
|
|
285
|
+
suggestionId: item.id,
|
|
286
|
+
...(item.origin === undefined ? {} : { origin: item.origin }),
|
|
287
|
+
},
|
|
288
|
+
});
|
|
311
289
|
}
|
|
312
290
|
// Nothing touches the live head until every downloaded revision and blob verifies.
|
|
313
291
|
for (const bytes of blobs.values())
|
|
@@ -333,12 +311,17 @@ export function connectHub(profile, theories, confirm, createMission, options =
|
|
|
333
311
|
const terminal = original.revisions.find(({ ref }) => sameExactPatchRef(ref, input.patch));
|
|
334
312
|
if (!terminal)
|
|
335
313
|
throw new Error("Patch is not in this Profile");
|
|
314
|
+
if (original.revisions.some((revision) => revision !== terminal && PATCH_MISSIONS_PROPERTY in revision.metadata.properties))
|
|
315
|
+
throw new Error("Cannot publish a Patch with private Mission pointers in a pinned base");
|
|
316
|
+
const { metadata } = reifyProfileMissions(revisionContent(terminal), current.log, resolvePatchBundle(original), {
|
|
317
|
+
missionIds: input.missions ?? [],
|
|
318
|
+
});
|
|
336
319
|
const packaged = {
|
|
337
320
|
...revisionContent(terminal),
|
|
338
321
|
metadata: {
|
|
339
|
-
...
|
|
322
|
+
...metadata,
|
|
340
323
|
properties: {
|
|
341
|
-
...
|
|
324
|
+
...metadata.properties,
|
|
342
325
|
"patch:title": input.title,
|
|
343
326
|
...(input.description === undefined ? {} : { "patch:description": input.description }),
|
|
344
327
|
},
|
|
@@ -363,12 +346,16 @@ export function connectHub(profile, theories, confirm, createMission, options =
|
|
|
363
346
|
throw new Error("A shared Mission needs a title");
|
|
364
347
|
const visibility = input.visibility ?? "unlisted";
|
|
365
348
|
const current = await profile.read();
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
.findLast((entry) => entry.mission.id === input.mission)?.mission;
|
|
369
|
-
if (!mission)
|
|
349
|
+
const revision = latestMissionRevision(current.log, input.mission);
|
|
350
|
+
if (!revision)
|
|
370
351
|
throw new Error("Unknown Mission");
|
|
371
|
-
const {
|
|
352
|
+
const { entry, position } = revision;
|
|
353
|
+
const { mission } = entry;
|
|
354
|
+
const { bundle, skills } = missionBundle(current.patches, mission, title, {
|
|
355
|
+
missionId: mission.id,
|
|
356
|
+
logEntryId: entry.id,
|
|
357
|
+
logPosition: position,
|
|
358
|
+
});
|
|
372
359
|
if (!(await confirm({
|
|
373
360
|
kind: "hub.share",
|
|
374
361
|
title: "Share " + title,
|
package/dist/learning.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare function openLearningReader<S>(profileDir: string, theories: read
|
|
|
33
33
|
surface: import("@mmon-co/ncept-core").SurfaceId;
|
|
34
34
|
about: readonly NodeId[];
|
|
35
35
|
closed: boolean;
|
|
36
|
+
closedAt?: string;
|
|
36
37
|
closing?: string;
|
|
37
38
|
mission?: string;
|
|
38
39
|
parent?: string;
|
|
@@ -79,6 +80,7 @@ export declare class LearningHost<S> {
|
|
|
79
80
|
retireMission(id: string, outcome: "achieved" | "abandoned"): Promise<void>;
|
|
80
81
|
begin(intent: SessionIntent): Promise<HostSession>;
|
|
81
82
|
open(input: SessionOpening): Promise<HostSession>;
|
|
83
|
+
private requireRefinedSection;
|
|
82
84
|
switchMode(session: LocalSession, to: ModeSwitch): Promise<void>;
|
|
83
85
|
context(session: LocalSession, view?: LearningView<S>): Promise<{
|
|
84
86
|
missions: {
|
package/dist/learning.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { isMission, isMissionRevision, isRunActiveChange, isRunPastEntry, isRunRetirement, lessonHere, nodeCascadedProperty, readMissionPath, readMissionRun, retire, selectGraph, setActive, tagIndex, } from "@mmon-co/ncept-core";
|
|
2
|
+
import { CHECKED_IN_PROPERTY, checkInRequired, pathProperty, sectionCoarseNodes, } from "@mmon-co/ncept-default-theory/path";
|
|
3
|
+
import { DEFAULT_THEORY_ID, homeDefaultRecords } from "@mmon-co/ncept-default-theory/state";
|
|
2
4
|
import { join } from "node:path";
|
|
3
5
|
import { lock } from "proper-lockfile";
|
|
4
6
|
import { openProfile } from "./directory.js";
|
|
@@ -10,9 +12,59 @@ import { mechanics } from "./mechanics.js";
|
|
|
10
12
|
import { ENTRY_KINDS, isSurface, modeEntry } from "./inputs.js";
|
|
11
13
|
import { object, parsePiSession } from "./sessions.js";
|
|
12
14
|
import { sessionLength } from "./session-policy.js";
|
|
13
|
-
function
|
|
15
|
+
function dueCheckIn(view, run, path, reading, closed, touches) {
|
|
16
|
+
if (run.retired || view.theory.id !== DEFAULT_THEORY_ID)
|
|
17
|
+
return;
|
|
18
|
+
const here = lessonHere(reading);
|
|
19
|
+
const section = here ? reading.sections.indexOf(here.section) : reading.sections.length;
|
|
20
|
+
const milestone = path.sections[section - 1]?.milestone;
|
|
21
|
+
const final = !here && milestone !== undefined ? true : undefined;
|
|
22
|
+
const required = checkInRequired(view.graph, path, milestone);
|
|
23
|
+
const stamp = milestone && pathProperty(view.graph, milestone, CHECKED_IN_PROPERTY);
|
|
24
|
+
let source;
|
|
25
|
+
if (milestone) {
|
|
26
|
+
for (const past of run.past) {
|
|
27
|
+
const session = past.kind === "session" ? closed.get(past.session) : undefined;
|
|
28
|
+
if (!session?.closedAt || (source && session.closedAt <= source.closedAt))
|
|
29
|
+
continue;
|
|
30
|
+
if (!final && typeof stamp === "string" && session.closedAt <= stamp)
|
|
31
|
+
continue;
|
|
32
|
+
if (touches(session.surface, milestone))
|
|
33
|
+
source = { sessionId: session.id, closedAt: session.closedAt };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!source && !required)
|
|
37
|
+
return;
|
|
38
|
+
const context = { ...(milestone === undefined ? {} : { milestone }), ...(final ? { final } : {}) };
|
|
39
|
+
return {
|
|
40
|
+
checkIn: { ...context, required },
|
|
41
|
+
entry: { kind: "checkpoint", missionId: run.mission, ...context, ...source, outcome: { kind: "cleared" } },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function readMissionStates(view, complete = false) {
|
|
14
45
|
const projection = view.theory.project(view.graph, view.state);
|
|
15
|
-
const
|
|
46
|
+
const states = sessionStates(view.profile);
|
|
47
|
+
const sessions = runs(states);
|
|
48
|
+
const closed = new Map(states.filter(({ closed }) => closed).map((session) => [session.id, session]));
|
|
49
|
+
let recordNodes;
|
|
50
|
+
const touches = (surface, node) => {
|
|
51
|
+
if (!recordNodes) {
|
|
52
|
+
recordNodes = new Map();
|
|
53
|
+
const { records, current } = homeDefaultRecords(view.graph, view.observations, view.now);
|
|
54
|
+
for (const record of records) {
|
|
55
|
+
if (!record.surface)
|
|
56
|
+
continue;
|
|
57
|
+
const homes = current.get(record.id);
|
|
58
|
+
if (!homes?.size)
|
|
59
|
+
continue;
|
|
60
|
+
const nodes = recordNodes.get(record.surface) ?? new Set();
|
|
61
|
+
for (const home of homes)
|
|
62
|
+
nodes.add(home);
|
|
63
|
+
recordNodes.set(record.surface, nodes);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return recordNodes.get(surface)?.has(node) ?? false;
|
|
67
|
+
};
|
|
16
68
|
return missions(view.profile).map((mission) => {
|
|
17
69
|
const run = missionRun(view.profile, mission.id);
|
|
18
70
|
const context = { graph: view.graph, projection, observations: view.observations, activities: [] };
|
|
@@ -24,29 +76,27 @@ function readMissions(view, complete = false) {
|
|
|
24
76
|
minutes: sessionLength(localSettings(view.profile)),
|
|
25
77
|
...(run.retired ? { retired: run.retired } : {}),
|
|
26
78
|
});
|
|
27
|
-
const itinerary = path
|
|
79
|
+
const itinerary = path && readMissionPath(path, view.theory, context);
|
|
80
|
+
const due = path && itinerary && dueCheckIn(view, run, path, itinerary, closed, touches);
|
|
28
81
|
const structured = itinerary?.sections.flatMap(({ lessons }) => lessons) ?? [];
|
|
29
|
-
|
|
82
|
+
const reading = {
|
|
30
83
|
mission,
|
|
31
84
|
run: readMissionRun(run, sessions, complete ? run.past.length : 20),
|
|
32
85
|
path: itinerary,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!stop.checkpoint || stop.checkpoint.required)
|
|
36
|
-
return true;
|
|
37
|
-
const progress = view.theory.progress(view.graph, projection, stop.nodes);
|
|
38
|
-
return stop.nodes.some((node) => !progress[node] || progress[node].status === "open");
|
|
39
|
-
})
|
|
40
|
-
.map((lesson, index) => ({
|
|
86
|
+
...(due ? { checkIn: due.checkIn } : {}),
|
|
87
|
+
next: (path?.future ?? []).map((lesson, index) => ({
|
|
41
88
|
...(structured.find((item) => item.kind === lesson.kind &&
|
|
42
89
|
item.tag === lesson.tag &&
|
|
43
90
|
JSON.stringify(item.nodes) === JSON.stringify(lesson.nodes)) ?? { ...lesson, number: index + 1, cleared: false }),
|
|
44
|
-
name: lesson.name ??
|
|
45
|
-
lesson.nodes.map((node) => stringProperty(view.graph, node, "display:label", node)).join(", "),
|
|
91
|
+
name: lesson.name ?? lesson.nodes.map((node) => stringProperty(view.graph, node, "display:label", node)).join(", "),
|
|
46
92
|
})),
|
|
47
93
|
};
|
|
94
|
+
return { reading, entry: due?.entry };
|
|
48
95
|
});
|
|
49
96
|
}
|
|
97
|
+
function readMissions(view, complete = false) {
|
|
98
|
+
return readMissionStates(view, complete).map(({ reading }) => reading);
|
|
99
|
+
}
|
|
50
100
|
/** Read current learning state without day processing, receipts or model calls. */
|
|
51
101
|
export async function openLearningReader(profileDir, theories) {
|
|
52
102
|
const profile = await openProfile(profileDir, theories, { readOnly: true });
|
|
@@ -122,14 +172,23 @@ function lessonAtEntry(session, graph, readings) {
|
|
|
122
172
|
function sessionTitle(session, profile, label) {
|
|
123
173
|
const entry = session.entry;
|
|
124
174
|
const mode = session.mode.charAt(0).toUpperCase() + session.mode.slice(1);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
175
|
+
let title = mode;
|
|
176
|
+
if (entry?.kind === "checkpoint") {
|
|
177
|
+
const name = missions(profile).find((mission) => mission.id === entry.missionId)?.statement;
|
|
178
|
+
title = "Check-in" + (name ? " · " + name : "");
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const name = entry?.kind === "mission"
|
|
182
|
+
? missions(profile).find((mission) => mission.id === entry.id)?.statement
|
|
183
|
+
: entry?.kind === "target"
|
|
184
|
+
? label(entry.node)
|
|
185
|
+
: entry?.kind === "goal"
|
|
186
|
+
? entry.text
|
|
187
|
+
: undefined;
|
|
188
|
+
if (name)
|
|
189
|
+
title += " · " + name;
|
|
190
|
+
}
|
|
191
|
+
return title.slice(0, 200);
|
|
133
192
|
}
|
|
134
193
|
function identity() {
|
|
135
194
|
return crypto.randomUUID();
|
|
@@ -385,15 +444,15 @@ export class LearningHost {
|
|
|
385
444
|
async begin(intent) {
|
|
386
445
|
if (intent.kind === "new-mission")
|
|
387
446
|
return this.open({ mode: "charting" });
|
|
388
|
-
const
|
|
389
|
-
if (!
|
|
447
|
+
const state = readMissionStates(await this.runtime.snapshot()).find(({ reading }) => reading.mission.id === intent.missionId);
|
|
448
|
+
if (!state || state.reading.run.retired?.outcome === "abandoned")
|
|
390
449
|
throw new Error("Mission is not available");
|
|
391
|
-
const { mission, run, next, path } = reading;
|
|
450
|
+
const { mission, run, next, path } = state.reading;
|
|
392
451
|
const entry = { kind: "mission", id: mission.id };
|
|
393
452
|
if (intent.kind === "continue" && run.active)
|
|
394
453
|
return this.open({ mode: "empty", resume: run.active });
|
|
395
|
-
if (run.retired
|
|
396
|
-
throw new Error("
|
|
454
|
+
if (run.retired)
|
|
455
|
+
throw new Error("This Mission is finished");
|
|
397
456
|
if (intent.kind === "skip-lesson" || intent.kind === "skip-to")
|
|
398
457
|
return this.open({ mode: "lesson", skip: { ...intent, mission: mission.id } });
|
|
399
458
|
if (intent.kind === "tell-tutor" && !intent.request.trim())
|
|
@@ -407,18 +466,17 @@ export class LearningHost {
|
|
|
407
466
|
}
|
|
408
467
|
if (intent.kind === "tell-tutor" || intent.kind === "revise-route" || !mission.targets.length)
|
|
409
468
|
return this.open({ mode: "charting", entry: { kind: "mission", id: mission.id } });
|
|
410
|
-
if (
|
|
411
|
-
|
|
469
|
+
if (state.entry)
|
|
470
|
+
return this.open({ mode: "charting", entry: state.entry });
|
|
412
471
|
const stop = next[0];
|
|
413
472
|
if (!stop)
|
|
414
473
|
throw new Error("This Mission has no following stop; revise the route or finish it");
|
|
415
|
-
if (stop.checkpoint)
|
|
416
|
-
return this.open({ mode: "charting", entry: { kind: "mission", id: mission.id } });
|
|
417
474
|
return this.open({ mode: "lesson", entry });
|
|
418
475
|
}
|
|
419
476
|
async open(input) {
|
|
420
477
|
const skipMission = input.skip?.mission;
|
|
421
478
|
let skipped = [];
|
|
479
|
+
let skipSection;
|
|
422
480
|
if (input.skip) {
|
|
423
481
|
if (input.resume || input.entry)
|
|
424
482
|
throw new Error("A skip cannot resume or supply an entry");
|
|
@@ -436,19 +494,15 @@ export class LearningHost {
|
|
|
436
494
|
const skip = input.skip;
|
|
437
495
|
const index = skip.kind === "skip-lesson"
|
|
438
496
|
? stops.findIndex((stop, position) => position > now && !stop.cleared)
|
|
439
|
-
: stops.findIndex((stop) => stop.kind === skip.stop.kind &&
|
|
440
|
-
stop.number === skip.stop.number &&
|
|
441
|
-
stop.checkpoint?.milestone === skip.stop.checkpoint?.milestone);
|
|
497
|
+
: stops.findIndex((stop) => stop.kind === skip.stop.kind && stop.number === skip.stop.number);
|
|
442
498
|
if (index < 0 || !stops[index])
|
|
443
499
|
throw new Error("This Mission has no following stop; revise the route or finish it");
|
|
444
500
|
if (now < 0 || index <= now || stops[index].cleared)
|
|
445
501
|
throw new Error("Choose an uncleared stop after the current Lesson");
|
|
446
|
-
skipped = stops.slice(now, index).filter((stop) => stop.numbered && !stop.cleared
|
|
502
|
+
skipped = stops.slice(now, index).filter((stop) => stop.numbered && !stop.cleared);
|
|
447
503
|
const stop = stops[index];
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
entry: { kind: "mission", id: reading.mission.id },
|
|
451
|
-
};
|
|
504
|
+
skipSection = path.sections.find(({ lessons }) => lessons.includes(stop));
|
|
505
|
+
input = { mode: "lesson", entry: { kind: "mission", id: reading.mission.id } };
|
|
452
506
|
}
|
|
453
507
|
const view = await this.runtime.snapshot();
|
|
454
508
|
const known = sessionStates(view.profile);
|
|
@@ -494,6 +548,9 @@ export class LearningHost {
|
|
|
494
548
|
const mission = missionId ? missions(view.profile).find(({ id }) => id === missionId) : undefined;
|
|
495
549
|
if (missionId && !mission)
|
|
496
550
|
throw new Error("Unknown Mission");
|
|
551
|
+
// Resuming an open Lesson stays possible, so Continue never strands an active run.
|
|
552
|
+
if (mode === "lesson" && mission && !resumed && (entry?.kind === "mission" || skipSection))
|
|
553
|
+
this.requireRefinedSection(view, mission.id, skipSection);
|
|
497
554
|
const about = (mode === "lesson" && entry?.kind === "mission" ? undefined : resumed?.about) ??
|
|
498
555
|
(entry?.kind === "target"
|
|
499
556
|
? [entry.node]
|
|
@@ -574,12 +631,22 @@ export class LearningHost {
|
|
|
574
631
|
this.pendingSwitch = undefined;
|
|
575
632
|
return session;
|
|
576
633
|
}
|
|
634
|
+
requireRefinedSection(view, missionId, destination) {
|
|
635
|
+
if (view.theory.id !== DEFAULT_THEORY_ID)
|
|
636
|
+
return;
|
|
637
|
+
const path = readMissions(view).find(({ mission }) => mission.id === missionId)?.path;
|
|
638
|
+
const here = path && lessonHere(path)?.section;
|
|
639
|
+
if ([here, destination].some((section) => section && sectionCoarseNodes(view.graph, section).length > 0))
|
|
640
|
+
throw new Error("Complete the check-in before starting the next Lesson");
|
|
641
|
+
}
|
|
577
642
|
async switchMode(session, to) {
|
|
578
643
|
const view = await this.runtime.snapshot();
|
|
579
644
|
const selected = this.mode(view.theory, session.mode, session.entry);
|
|
580
645
|
if (!selected?.switches.some((allowed) => allowed.mode === to.mode && allowed.then === to.then))
|
|
581
646
|
throw new Error("This mode does not allow that switch");
|
|
582
647
|
this.mode(view.theory, to.mode, to.entry);
|
|
648
|
+
if (to.mode === "lesson" && to.entry?.kind === "mission")
|
|
649
|
+
this.requireRefinedSection(view, to.entry.id);
|
|
583
650
|
if (to.then === "here") {
|
|
584
651
|
const missionId = to.entry?.kind === "mission"
|
|
585
652
|
? to.entry.id
|
package/dist/runtime.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface LocalSession extends HostSession {
|
|
|
6
6
|
readonly surface: SurfaceId;
|
|
7
7
|
readonly about: readonly NodeId[];
|
|
8
8
|
readonly closed: boolean;
|
|
9
|
+
readonly closedAt?: string;
|
|
9
10
|
/** Identifies a pending close; resuming the Session clears it. */
|
|
10
11
|
readonly closing?: string;
|
|
11
12
|
readonly mission?: string;
|
package/dist/runtime.js
CHANGED
|
@@ -26,7 +26,7 @@ export function sessionStates(profile) {
|
|
|
26
26
|
const states = new Map();
|
|
27
27
|
for (const entry of profile.log) {
|
|
28
28
|
const payload = localPayload(entry, "local.session");
|
|
29
|
-
if (payload && object(payload.session)) {
|
|
29
|
+
if (payload && isObservation(entry) && object(payload.session)) {
|
|
30
30
|
const session = payload.session;
|
|
31
31
|
if (!nonempty(session.id) ||
|
|
32
32
|
!isSurface(session.surface) ||
|
|
@@ -38,6 +38,7 @@ export function sessionStates(profile) {
|
|
|
38
38
|
surface: session.surface,
|
|
39
39
|
mode: session.mode,
|
|
40
40
|
closed: session.closed,
|
|
41
|
+
...(session.closed ? { closedAt: entry.at } : {}),
|
|
41
42
|
...(typeof session.closing === "string" ? { closing: session.closing } : {}),
|
|
42
43
|
about: nodeIds(session.about),
|
|
43
44
|
...(session.entry === undefined ? {} : { entry: modeEntry(session.entry) }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmon-co/ncept-local",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "bun run --cwd ../
|
|
35
|
+
"build": "bun run --cwd ../default-theory build && tsc -p tsconfig.build.json",
|
|
36
36
|
"prepack": "bun run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@mmon-co/ncept-core": "^0.4.0",
|
|
40
|
+
"@mmon-co/ncept-default-theory": "^3.0.0",
|
|
40
41
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
41
42
|
"proper-lockfile": "4.1.2"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@mmon-co/ncept-default-theory": "^3.0.0",
|
|
45
45
|
"@types/proper-lockfile": "^4.1.4",
|
|
46
46
|
"bun-types": "^1.3.14",
|
|
47
47
|
"typescript": "6.0.3"
|