@mmon-co/ncept-local 0.3.9 → 0.3.11
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/exchange.js +42 -2
- package/dist/host.d.ts +2 -1
- package/dist/hub.d.ts +2 -2
- package/dist/hub.js +53 -66
- package/dist/inputs.d.ts +1 -1
- package/dist/inputs.js +1 -3
- package/dist/learning.js +34 -61
- package/dist/session-policy.d.ts +0 -21
- package/dist/session-policy.js +0 -4
- package/package.json +1 -1
package/dist/exchange.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attachmentDigest, resolveNotebookRevision, isContentDigest, isMissionRevision, isNodeId, isPatchId, isProfileLogEntry, mergeProfileLogs, migrateTheoryProfile, resolveTheory, revisionDigest, } from "@mmon-co/ncept-core";
|
|
1
|
+
import { attachmentDigest, resolveNotebookRevision, isContentDigest, isMissionRevision, isNodeId, isPatchId, isProfileLogEntry, isRunActiveChange, 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"];
|
|
@@ -171,7 +171,11 @@ export function migrateLessonLog(files) {
|
|
|
171
171
|
throw new Error("Profile log digest mismatch");
|
|
172
172
|
const entries = decodeLog(bytes);
|
|
173
173
|
const missions = new Set(entries.filter(isMissionRevision).map(({ mission }) => mission.id));
|
|
174
|
+
const activeByMission = new Map();
|
|
175
|
+
const openReviews = new Map();
|
|
174
176
|
const nextEntries = entries.map((value) => {
|
|
177
|
+
if (isRunActiveChange(value))
|
|
178
|
+
activeByMission.set(value.mission, value);
|
|
175
179
|
if (!object(value))
|
|
176
180
|
return value;
|
|
177
181
|
if (value.kind === "run.past" && object(value.entry) && value.entry.kind === "session" && "stop" in value.entry) {
|
|
@@ -181,7 +185,31 @@ export function migrateLessonLog(files) {
|
|
|
181
185
|
const payload = value.payload;
|
|
182
186
|
if (value.by !== "platform" || !object(payload) || payload.kind !== "local.session" || !object(payload.session))
|
|
183
187
|
return value;
|
|
184
|
-
const { entry, mission:
|
|
188
|
+
const { entry, mission: attached, ...session } = payload.session;
|
|
189
|
+
if (typeof session.id === "string")
|
|
190
|
+
openReviews.delete(session.id);
|
|
191
|
+
if (object(entry) && entry.kind === "review") {
|
|
192
|
+
const { closing: _closing, ...state } = session;
|
|
193
|
+
const closed = { ...state, closed: true };
|
|
194
|
+
if (typeof attached === "string" && missions.has(attached)) {
|
|
195
|
+
if (session.closed === false && typeof session.id === "string")
|
|
196
|
+
openReviews.set(session.id, attached);
|
|
197
|
+
return {
|
|
198
|
+
...value,
|
|
199
|
+
payload: { ...payload, session: { ...closed, mission: attached, entry: { kind: "mission", id: attached } } },
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const node = Array.isArray(entry.nodes) ? entry.nodes.find(isNodeId) : undefined;
|
|
203
|
+
return {
|
|
204
|
+
...value,
|
|
205
|
+
payload: {
|
|
206
|
+
...payload,
|
|
207
|
+
session: node
|
|
208
|
+
? { ...closed, about: [node], entry: { kind: "target", node } }
|
|
209
|
+
: { ...closed, mode: "empty", about: [] },
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
185
213
|
if (!object(entry) || entry.kind !== "lesson" || !object(entry.lesson))
|
|
186
214
|
return value;
|
|
187
215
|
const lesson = entry.lesson;
|
|
@@ -202,6 +230,18 @@ export function migrateLessonLog(files) {
|
|
|
202
230
|
});
|
|
203
231
|
if (nextEntries.every((entry, index) => entry === entries[index]))
|
|
204
232
|
return files;
|
|
233
|
+
// Clear only the current Review pointer, keeping the original activity and past entries.
|
|
234
|
+
for (const { mission, active, id, at } of activeByMission.values()) {
|
|
235
|
+
if (active !== null && openReviews.get(active) === mission) {
|
|
236
|
+
nextEntries.push({
|
|
237
|
+
kind: "run.active",
|
|
238
|
+
id: "close-review-" + attachmentDigest(jsonBytes(id)),
|
|
239
|
+
at,
|
|
240
|
+
mission,
|
|
241
|
+
active: null,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
205
245
|
const next = new Map(files);
|
|
206
246
|
const log = logBytes(checkedLog(nextEntries));
|
|
207
247
|
const updated = { ...manifest, log: attachmentDigest(log) };
|
package/dist/host.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export type SessionIntent = Readonly<{
|
|
|
97
97
|
missionId: string;
|
|
98
98
|
request: string;
|
|
99
99
|
}> | Readonly<{
|
|
100
|
-
kind: "new-mission"
|
|
100
|
+
kind: "new-mission";
|
|
101
101
|
}>;
|
|
102
102
|
export interface Host {
|
|
103
103
|
readonly profile: ProfileDirectory;
|
|
@@ -128,6 +128,7 @@ export interface Host {
|
|
|
128
128
|
version: string;
|
|
129
129
|
title: string;
|
|
130
130
|
description?: string;
|
|
131
|
+
missions?: readonly string[];
|
|
131
132
|
}>): Promise<HubRelease>;
|
|
132
133
|
/**
|
|
133
134
|
* 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/inputs.d.ts
CHANGED
|
@@ -9,5 +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" | "
|
|
12
|
+
export declare const ENTRY_KINDS: ("mission" | "target" | "goal" | "checkpoint")[];
|
|
13
13
|
export declare function modeEntry(value: unknown): ModeEntry;
|
package/dist/inputs.js
CHANGED
|
@@ -173,7 +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", "
|
|
176
|
+
export const ENTRY_KINDS = ["goal", "mission", "target", "checkpoint"];
|
|
177
177
|
export function modeEntry(value) {
|
|
178
178
|
const input = record(value);
|
|
179
179
|
switch (input.kind) {
|
|
@@ -215,8 +215,6 @@ export function modeEntry(value) {
|
|
|
215
215
|
if (!isNodeId(input.node))
|
|
216
216
|
throw new Error("A target entry needs a Node");
|
|
217
217
|
return { kind: "target", node: input.node };
|
|
218
|
-
case "review":
|
|
219
|
-
return { kind: "review", nodes: nodeIds(input.nodes) };
|
|
220
218
|
case "checkpoint":
|
|
221
219
|
if (!nonempty(input.missionId) || (input.milestone !== undefined && !isNodeId(input.milestone)))
|
|
222
220
|
throw new Error("Invalid checkpoint entry");
|
package/dist/learning.js
CHANGED
|
@@ -9,7 +9,7 @@ import { hostTools } from "./host-tools.js";
|
|
|
9
9
|
import { mechanics } from "./mechanics.js";
|
|
10
10
|
import { ENTRY_KINDS, isSurface, modeEntry } from "./inputs.js";
|
|
11
11
|
import { object, parsePiSession } from "./sessions.js";
|
|
12
|
-
import {
|
|
12
|
+
import { sessionLength } from "./session-policy.js";
|
|
13
13
|
function readMissions(view, complete = false) {
|
|
14
14
|
const projection = view.theory.project(view.graph, view.state);
|
|
15
15
|
const sessions = runs(sessionStates(view.profile));
|
|
@@ -122,21 +122,14 @@ function lessonAtEntry(session, graph, readings) {
|
|
|
122
122
|
function sessionTitle(session, profile, label) {
|
|
123
123
|
const entry = session.entry;
|
|
124
124
|
const mode = session.mode.charAt(0).toUpperCase() + session.mode.slice(1);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
: entry?.kind === "goal"
|
|
134
|
-
? entry.text
|
|
135
|
-
: undefined;
|
|
136
|
-
if (name)
|
|
137
|
-
title += " · " + name;
|
|
138
|
-
}
|
|
139
|
-
return title.slice(0, 200);
|
|
125
|
+
const name = entry?.kind === "mission"
|
|
126
|
+
? missions(profile).find((mission) => mission.id === entry.id)?.statement
|
|
127
|
+
: entry?.kind === "target"
|
|
128
|
+
? label(entry.node)
|
|
129
|
+
: entry?.kind === "goal"
|
|
130
|
+
? entry.text
|
|
131
|
+
: undefined;
|
|
132
|
+
return (name ? mode + " · " + name : mode).slice(0, 200);
|
|
140
133
|
}
|
|
141
134
|
function identity() {
|
|
142
135
|
return crypto.randomUUID();
|
|
@@ -245,8 +238,11 @@ export class LearningHost {
|
|
|
245
238
|
return state;
|
|
246
239
|
}
|
|
247
240
|
mode(theory, mode, entry) {
|
|
248
|
-
if (entry)
|
|
241
|
+
if (entry) {
|
|
249
242
|
modeEntry(entry);
|
|
243
|
+
if (!ENTRY_KINDS.some((kind) => kind === entry.kind))
|
|
244
|
+
throw new Error("Unsupported Session entry");
|
|
245
|
+
}
|
|
250
246
|
const selected = theory.modes?.[mode];
|
|
251
247
|
if (theory.modes && !selected)
|
|
252
248
|
throw new Error("Unknown Theory mode: " + mode);
|
|
@@ -389,23 +385,6 @@ export class LearningHost {
|
|
|
389
385
|
async begin(intent) {
|
|
390
386
|
if (intent.kind === "new-mission")
|
|
391
387
|
return this.open({ mode: "charting" });
|
|
392
|
-
if (intent.kind === "review") {
|
|
393
|
-
const view = await this.runtime.snapshot();
|
|
394
|
-
const stop = reviewStop(view.theory, {
|
|
395
|
-
graph: view.graph,
|
|
396
|
-
projection: view.theory.project(view.graph, view.state),
|
|
397
|
-
observations: view.observations,
|
|
398
|
-
activities: [],
|
|
399
|
-
past: [],
|
|
400
|
-
now: view.now,
|
|
401
|
-
minutes: sessionLength(localSettings(view.profile)),
|
|
402
|
-
});
|
|
403
|
-
if (!stop?.nodes.length)
|
|
404
|
-
throw new Error("No review due");
|
|
405
|
-
return this.open({ mode: "lesson", entry: { kind: "review", nodes: stop.nodes } });
|
|
406
|
-
}
|
|
407
|
-
if (!("missionId" in intent))
|
|
408
|
-
throw new Error("Expected a Mission entry");
|
|
409
388
|
const reading = (await this.missionReadings()).find(({ mission }) => mission.id === intent.missionId);
|
|
410
389
|
if (!reading || reading.run.retired?.outcome === "abandoned")
|
|
411
390
|
throw new Error("Mission is not available");
|
|
@@ -428,11 +407,9 @@ export class LearningHost {
|
|
|
428
407
|
}
|
|
429
408
|
if (intent.kind === "tell-tutor" || intent.kind === "revise-route" || !mission.targets.length)
|
|
430
409
|
return this.open({ mode: "charting", entry: { kind: "mission", id: mission.id } });
|
|
431
|
-
const stop = next[0];
|
|
432
|
-
if (stop?.kind === "review")
|
|
433
|
-
return this.open({ mode: "lesson", entry: { kind: "review", nodes: stop.nodes }, mission: mission.id });
|
|
434
410
|
if (run.retired)
|
|
435
|
-
throw new Error("
|
|
411
|
+
throw new Error("This Mission is finished");
|
|
412
|
+
const stop = next[0];
|
|
436
413
|
if (!stop)
|
|
437
414
|
throw new Error("This Mission has no following stop; revise the route or finish it");
|
|
438
415
|
if (stop.checkpoint)
|
|
@@ -468,8 +445,10 @@ export class LearningHost {
|
|
|
468
445
|
throw new Error("Choose an uncleared stop after the current Lesson");
|
|
469
446
|
skipped = stops.slice(now, index).filter((stop) => stop.numbered && !stop.cleared && !stop.checkpoint);
|
|
470
447
|
const stop = stops[index];
|
|
471
|
-
|
|
472
|
-
|
|
448
|
+
input = {
|
|
449
|
+
mode: stop.checkpoint ? "charting" : "lesson",
|
|
450
|
+
entry: { kind: "mission", id: reading.mission.id },
|
|
451
|
+
};
|
|
473
452
|
}
|
|
474
453
|
const view = await this.runtime.snapshot();
|
|
475
454
|
const known = sessionStates(view.profile);
|
|
@@ -482,15 +461,13 @@ export class LearningHost {
|
|
|
482
461
|
id: imported.header.id,
|
|
483
462
|
surface,
|
|
484
463
|
mode: input.mode,
|
|
485
|
-
about: input.entry?.kind === "
|
|
486
|
-
? input.entry.
|
|
487
|
-
:
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
.flatMap((observation) => observation.nodes ?? observation.about ?? [])),
|
|
493
|
-
],
|
|
464
|
+
about: input.entry?.kind === "target"
|
|
465
|
+
? [input.entry.node]
|
|
466
|
+
: [
|
|
467
|
+
...new Set(view.observations
|
|
468
|
+
.filter((observation) => observation.surface === surface)
|
|
469
|
+
.flatMap((observation) => observation.nodes ?? observation.about ?? [])),
|
|
470
|
+
],
|
|
494
471
|
closed: true,
|
|
495
472
|
...(input.entry === undefined ? {} : { entry: input.entry }),
|
|
496
473
|
};
|
|
@@ -520,11 +497,9 @@ export class LearningHost {
|
|
|
520
497
|
const about = (mode === "lesson" && entry?.kind === "mission" ? undefined : resumed?.about) ??
|
|
521
498
|
(entry?.kind === "target"
|
|
522
499
|
? [entry.node]
|
|
523
|
-
:
|
|
524
|
-
?
|
|
525
|
-
:
|
|
526
|
-
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
527
|
-
: []);
|
|
500
|
+
: mission
|
|
501
|
+
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
502
|
+
: []);
|
|
528
503
|
for (const node of about)
|
|
529
504
|
if (!view.graph.nodes.some(({ id }) => id === node))
|
|
530
505
|
throw new Error("Missing Node " + node);
|
|
@@ -614,13 +589,11 @@ export class LearningHost {
|
|
|
614
589
|
const mission = missions(view.profile).find(({ id }) => id === missionId);
|
|
615
590
|
if (missionId && !mission)
|
|
616
591
|
throw new Error("Unknown Mission");
|
|
617
|
-
const about = to.entry?.kind === "
|
|
618
|
-
? to.entry.
|
|
619
|
-
:
|
|
620
|
-
?
|
|
621
|
-
:
|
|
622
|
-
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
623
|
-
: session.about;
|
|
592
|
+
const about = to.entry?.kind === "target"
|
|
593
|
+
? [to.entry.node]
|
|
594
|
+
: mission
|
|
595
|
+
? selectGraph(view.graph, { cone: { targets: mission.targets.map(({ node }) => node) } }).nodes.map(({ id }) => id)
|
|
596
|
+
: session.about;
|
|
624
597
|
for (const node of about)
|
|
625
598
|
if (!view.graph.nodes.some(({ id }) => id === node))
|
|
626
599
|
throw new Error("Missing Node " + node);
|
package/dist/session-policy.d.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
import type { PathContext, Theory } from "@mmon-co/ncept-core";
|
|
2
1
|
/** Profile learning preference; an unchosen Session length matches one unmeasured Lesson Node. */
|
|
3
2
|
export declare function sessionLength(values?: Readonly<{
|
|
4
3
|
sessionLength?: unknown;
|
|
5
4
|
}>): number;
|
|
6
|
-
/** Voluntary Review uses the Theory’s maintenance stop; blocking Reviews stay with their Lesson. */
|
|
7
|
-
export declare function reviewStop(theory: Pick<Theory<unknown>, "path">, context: PathContext): Readonly<{
|
|
8
|
-
kind: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
nodes: readonly import("@mmon-co/ncept-core").NodeId[];
|
|
11
|
-
numbered: boolean;
|
|
12
|
-
numberOffset?: number;
|
|
13
|
-
tag?: string;
|
|
14
|
-
milestone?: import("@mmon-co/ncept-core").NodeId;
|
|
15
|
-
checkpoint?: Readonly<{
|
|
16
|
-
milestone?: import("@mmon-co/ncept-core").NodeId;
|
|
17
|
-
required: boolean;
|
|
18
|
-
final?: true;
|
|
19
|
-
updates?: readonly {
|
|
20
|
-
patch: string;
|
|
21
|
-
title: string;
|
|
22
|
-
version: string;
|
|
23
|
-
}[];
|
|
24
|
-
}>;
|
|
25
|
-
}> | undefined;
|
package/dist/session-policy.js
CHANGED
|
@@ -7,7 +7,3 @@ export function sessionLength(values) {
|
|
|
7
7
|
throw new Error("Session length must be a positive number of minutes");
|
|
8
8
|
return minutes;
|
|
9
9
|
}
|
|
10
|
-
/** Voluntary Review uses the Theory’s maintenance stop; blocking Reviews stay with their Lesson. */
|
|
11
|
-
export function reviewStop(theory, context) {
|
|
12
|
-
return theory.path?.(context).future.find((stop) => stop.kind === "review" && !stop.numberOffset);
|
|
13
|
-
}
|