@mmon-co/ncept-local 0.3.10 → 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/host.d.ts CHANGED
@@ -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, canonicalJson, contentDigest, bundleForRevision, candidateRevision, exactPatchRefKey, isAttachment, isContentDigest, isMission, isMissionRevision, isPatchId, migrateTheoryPatchClosure, notebookSelection, reifyView, releasePrecedenceKey, resolveTheory, resolvePatchBundle, revisionContent, sameExactPatchRef, selectGraph, } from "@mmon-co/ncept-core";
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 entries = (list) => list?.map((entry) => ({
31
- ...entry,
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
- // The Hub records provenance itself and refuses it from a client.
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
- properties: { ...reified.metadata.properties, [MISSION_SUGGESTIONS]: canonicalJson([suggestion]) },
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 = suggestedMissions(adopted, contents);
298
- const existing = new Set(current.log.filter(isMissionRevision).map(({ mission }) => mission.id));
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 { mission, preselected } of suggestions) {
301
- if (existing.has(mission.id))
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: mission.statement,
307
- detail: { statement: mission.statement },
308
- defaultAccepted: preselected,
271
+ description: item.statement,
272
+ detail: { statement: item.statement },
273
+ defaultAccepted: item.preselected === true,
309
274
  }))
310
- selectedMissions.push(mission);
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
- ...terminal.metadata,
322
+ ...metadata,
340
323
  properties: {
341
- ...terminal.metadata.properties,
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 mission = current.log
367
- .filter(isMissionRevision)
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 { bundle, skills } = missionBundle(current.patches, mission, title);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmon-co/ncept-local",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",