@mmon-co/ncept-local 0.3.9 → 0.3.10

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 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: _mission, ...session } = payload.session;
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" | "review";
100
+ kind: "new-mission";
101
101
  }>;
102
102
  export interface Host {
103
103
  readonly profile: ProfileDirectory;
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" | "review" | "checkpoint")[];
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", "review", "checkpoint"];
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 { reviewStop, sessionLength } from "./session-policy.js";
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
- let title = mode;
126
- if (entry?.kind === "review")
127
- title = "Review · " + entry.nodes.length + " due";
128
- else {
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;
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("No review is due for this finished Mission");
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
- const entry = stop.kind === "review" ? { kind: "review", nodes: stop.nodes } : { kind: "mission", id: reading.mission.id };
472
- input = { mode: stop.checkpoint ? "charting" : "lesson", entry };
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 === "review"
486
- ? input.entry.nodes
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
- ],
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
- : entry?.kind === "review"
524
- ? entry.nodes
525
- : mission
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 === "review"
618
- ? to.entry.nodes
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;
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);
@@ -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;
@@ -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
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmon-co/ncept-local",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",