@miadi/inquiry-weave 0.15.1 → 0.16.1

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.
Files changed (47) hide show
  1. package/README.md +21 -0
  2. package/dist/chronicle-dsl.d.ts +5 -0
  3. package/dist/chronicle-dsl.d.ts.map +1 -1
  4. package/dist/chronicle-dsl.js +39 -5
  5. package/dist/chronicle-dsl.js.map +1 -1
  6. package/dist/chronicle-terminal.d.ts +30 -1
  7. package/dist/chronicle-terminal.d.ts.map +1 -1
  8. package/dist/chronicle-terminal.js +79 -4
  9. package/dist/chronicle-terminal.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +31 -1
  12. package/dist/cli.js.map +1 -1
  13. package/dist/foundation-dsl.d.ts +51 -0
  14. package/dist/foundation-dsl.d.ts.map +1 -0
  15. package/dist/foundation-dsl.js +89 -0
  16. package/dist/foundation-dsl.js.map +1 -0
  17. package/dist/foundation.d.ts +134 -0
  18. package/dist/foundation.d.ts.map +1 -0
  19. package/dist/foundation.js +380 -0
  20. package/dist/foundation.js.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/markdown-directives.d.ts +72 -0
  26. package/dist/markdown-directives.d.ts.map +1 -0
  27. package/dist/markdown-directives.js +285 -0
  28. package/dist/markdown-directives.js.map +1 -0
  29. package/dist/mcp-server.js +41 -4
  30. package/dist/mcp-server.js.map +1 -1
  31. package/dist/mint.d.ts +47 -1
  32. package/dist/mint.d.ts.map +1 -1
  33. package/dist/mint.js +126 -0
  34. package/dist/mint.js.map +1 -1
  35. package/dist/references.d.ts +12 -0
  36. package/dist/references.d.ts.map +1 -0
  37. package/dist/references.js +12 -0
  38. package/dist/references.js.map +1 -0
  39. package/dist/review.d.ts +12 -0
  40. package/dist/review.d.ts.map +1 -1
  41. package/dist/review.js +3 -3
  42. package/dist/review.js.map +1 -1
  43. package/dist/text-references.d.ts +38 -2
  44. package/dist/text-references.d.ts.map +1 -1
  45. package/dist/text-references.js +168 -19
  46. package/dist/text-references.js.map +1 -1
  47. package/package.json +7 -2
@@ -0,0 +1,380 @@
1
+ /**
2
+ * The foundation seam — a foundation packet entering an episode, in the shape
3
+ * the review seam set (jgwill/Miadi#630): one reusable `foundation:<slug>`
4
+ * node on the wheel, one `chronicle:<episode>` → `foundation:<slug>` edge whose
5
+ * relationship type names what the episode uses the packet for, and an entry
6
+ * in `episode.yaml` keeping the version the episode read.
7
+ *
8
+ * Two sources (SPEC §10, jgwill/Miadi#713):
9
+ * - `package`: a packet from `@miadi/foundations`, looked up by slug. The
10
+ * lookup is the caller's: the app reads the package it ships, a terminal
11
+ * asks a front or a directory. This file fetches nothing on its own.
12
+ * - `episode`: a small packet the episode wrote itself under
13
+ * `foundations/<topic>/`. It must exist in the vessel before it is held.
14
+ *
15
+ * Rules kept from the review seam: the manifest entry is written once and
16
+ * never overwritten (a later call fills missing keys only), one ordered node
17
+ * pair is one edge so a hand-made edge keeps its relation, and the wheel
18
+ * projection never throws — a wheel that is down answers `pending`.
19
+ */
20
+ import { readFile, writeFile, stat } from "node:fs/promises";
21
+ import { existsSync } from "node:fs";
22
+ import { dirname, join } from "node:path";
23
+ import { Scalar, isMap, isScalar, isSeq, parseDocument } from "yaml";
24
+ import { DEFAULT_FOUNDATION_RELATION, FOUNDATION_ENTRY_KEYS, FOUNDATION_NODE_KIND, episodeFoundationPath, foundationNodeId, isFoundationSlug, toEpisodeFoundationEntry, } from "@miadi/episodic-memory-schema";
25
+ import { missingManifestRemedy } from "./episode.js";
26
+ import { parseFoundationUri, foundationRoute } from "./foundation-dsl.js";
27
+ import { edgesFrom, failure, wheelJson } from "./review.js";
28
+ export class FoundationError extends Error {
29
+ code;
30
+ constructor(code, message) {
31
+ super(message);
32
+ this.code = code;
33
+ this.name = "FoundationError";
34
+ }
35
+ }
36
+ /**
37
+ * The first `# ` heading of a README, or undefined. A line scan with no
38
+ * backtracking: the regex it replaces took 20 s on one heading holding 40,000
39
+ * spaces (jgwill/Miadi#713 review, F4). Only the first 64 KB are read, and a
40
+ * closing run of `#` is dropped only after whitespace, as CommonMark does
41
+ * (`# C#` stays "C#").
42
+ */
43
+ export function readmeTitle(markdown) {
44
+ const text = markdown.length > 65_536 ? markdown.slice(0, 65_536) : markdown;
45
+ let at = 0;
46
+ while (at < text.length) {
47
+ const nl = text.indexOf("\n", at);
48
+ const line = text.slice(at, nl === -1 ? text.length : nl).replace(/\r$/, "");
49
+ if (line.startsWith("# ") || line.startsWith("#\t")) {
50
+ let end = line.length;
51
+ while (end > 1 && (line[end - 1] === " " || line[end - 1] === "\t"))
52
+ end--;
53
+ let hashes = end;
54
+ while (hashes > 1 && line[hashes - 1] === "#")
55
+ hashes--;
56
+ if (hashes < end && (line[hashes - 1] === " " || line[hashes - 1] === "\t"))
57
+ end = hashes;
58
+ const title = line.slice(1, end).trim();
59
+ if (title)
60
+ return title;
61
+ }
62
+ if (nl === -1)
63
+ break;
64
+ at = nl + 1;
65
+ }
66
+ return undefined;
67
+ }
68
+ /**
69
+ * A lookup over packets on this host: `<root>/<slug>/README.md`. `version`
70
+ * is the version of whatever distributed that root, when the caller knows it.
71
+ */
72
+ export function foundationLookupFromDir(root, version) {
73
+ return async (slug) => {
74
+ if (!isFoundationSlug(slug))
75
+ return null;
76
+ let readme;
77
+ try {
78
+ readme = await readFile(join(root, slug, "README.md"), "utf8");
79
+ }
80
+ catch {
81
+ return null;
82
+ }
83
+ const read = version ?? (await bundledVersion(root, slug));
84
+ return { slug, title: readmeTitle(readme) ?? slug, ...(read ? { version: read } : {}) };
85
+ };
86
+ }
87
+ /**
88
+ * The version of a packet in an installed `@miadi/foundations` bundle: the
89
+ * source commit its manifest records for that packet, `+dirty` when the
90
+ * packet had uncommitted changes at bundle time. That names the content;
91
+ * the package version does not, because a bundle built from the working tree
92
+ * keeps the last release's number (jgwill/Miadi#713 review, F2 and F12).
93
+ * Undefined when `root` is not an installed bundle.
94
+ */
95
+ export async function bundledVersion(root, slug) {
96
+ try {
97
+ const manifest = JSON.parse(await readFile(join(root, "..", "manifest.json"), "utf8"));
98
+ const entry = manifest.foundations?.find((f) => f.slug === slug);
99
+ return entry?.commit ? `${entry.commit}${entry.dirty ? "+dirty" : ""}` : undefined;
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ }
105
+ /**
106
+ * A lookup over a Miadi front's public JSON, `GET <base>/api/foundations/<slug>`.
107
+ * Only the given base is asked, so a caller cannot make a server fetch an
108
+ * address of its choosing.
109
+ */
110
+ export function foundationLookupFromFront(base, options = {}) {
111
+ const origin = base.replace(/\/+$/, "");
112
+ return async (slug) => {
113
+ if (!isFoundationSlug(slug))
114
+ return null;
115
+ const controller = new AbortController();
116
+ const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 8_000);
117
+ try {
118
+ const response = await (options.fetchImpl ?? fetch)(`${origin}/api/foundations/${encodeURIComponent(slug)}`, { signal: controller.signal });
119
+ if (response.status === 404)
120
+ return null;
121
+ if (!response.ok)
122
+ throw new Error(`HTTP ${response.status}`);
123
+ const body = (await response.json());
124
+ const f = body.foundation;
125
+ if (!f || f.slug !== slug)
126
+ return null;
127
+ return {
128
+ slug,
129
+ title: typeof f.title === "string" && f.title ? f.title : slug,
130
+ ...(typeof f.version === "string" ? { version: f.version } : {}),
131
+ ...(Array.isArray(f.fields) ? { fields: f.fields.filter((x) => typeof x === "string") } : {}),
132
+ url: `${origin}${foundationRoute({ slug })}`,
133
+ };
134
+ }
135
+ finally {
136
+ clearTimeout(timer);
137
+ }
138
+ };
139
+ }
140
+ /**
141
+ * Read the packet an input names: a slug, `miadi-foundation:<slug>`, or (for
142
+ * an episode's own packet) the topic. A file or fragment in the address is
143
+ * ignored: an episode holds the packet, not one file of it.
144
+ */
145
+ export function requireFoundationSlug(raw) {
146
+ const text = typeof raw === "string" ? raw.trim() : "";
147
+ if (isFoundationSlug(text))
148
+ return text;
149
+ const parsed = parseFoundationUri(text);
150
+ if (parsed)
151
+ return parsed.slug;
152
+ throw new FoundationError("invalid_foundation", `foundation '${String(raw)}' is not a packet name or a miadi-foundation: address`);
153
+ }
154
+ /** An episode's own packet: `foundations/<topic>/` with a README, read for its title. */
155
+ export async function readEpisodePacket(episodeDir, slug) {
156
+ if (!isFoundationSlug(slug))
157
+ throw new FoundationError("invalid_foundation", `'${slug}' is not a packet directory name`);
158
+ const dir = join(episodeDir, episodeFoundationPath(slug));
159
+ try {
160
+ if (!(await stat(dir)).isDirectory())
161
+ throw new Error("not a directory");
162
+ }
163
+ catch {
164
+ throw new FoundationError("foundation_not_found", `the episode holds no ${episodeFoundationPath(slug)}/ — write the packet there first, then hold it`);
165
+ }
166
+ let title;
167
+ try {
168
+ title = readmeTitle(await readFile(join(dir, "README.md"), "utf8"));
169
+ }
170
+ catch {
171
+ title = undefined;
172
+ }
173
+ return { slug, title: title ?? slug };
174
+ }
175
+ /**
176
+ * The entry as a YAML map. Every value is a quoted string: an ISO `added` or a
177
+ * version like `0.1` left plain is a timestamp or a number to a YAML 1.1
178
+ * reader (PyYAML, js-yaml), never the string written (#713 review, F13).
179
+ */
180
+ function entryNode(doc, entry) {
181
+ const map = doc.createNode({});
182
+ for (const key of FOUNDATION_ENTRY_KEYS) {
183
+ const value = entry[key];
184
+ if (value !== undefined && value !== "")
185
+ map.set(key, quoted(doc, value));
186
+ }
187
+ return map;
188
+ }
189
+ function quoted(doc, value) {
190
+ const node = doc.createNode(value);
191
+ node.type = Scalar.QUOTE_SINGLE;
192
+ return node;
193
+ }
194
+ const sameEntry = (a, b) => a !== null && a.slug === b.slug && a.source === b.source;
195
+ /**
196
+ * Add a packet to `episode.yaml`'s `foundations:` list, or fill the keys an
197
+ * existing entry lacks. Comments, key order and every other field survive.
198
+ * Refuses a `foundations` key that is not a list.
199
+ */
200
+ export async function upsertEpisodeFoundation(input) {
201
+ if (!existsSync(input.episodeYamlPath)) {
202
+ throw new FoundationError("foundation_manifest_conflict", missingManifestRemedy(dirname(input.episodeYamlPath)));
203
+ }
204
+ const doc = parseDocument(await readFile(input.episodeYamlPath, "utf8"));
205
+ if (doc.errors.length > 0) {
206
+ throw new FoundationError("foundation_manifest_conflict", `unreadable episode.yaml ${input.episodeYamlPath}: ${doc.errors[0].message}`);
207
+ }
208
+ if (!isMap(doc.contents)) {
209
+ throw new FoundationError("foundation_manifest_conflict", `episode.yaml ${input.episodeYamlPath} is not a mapping`);
210
+ }
211
+ const list = doc.get("foundations", true);
212
+ let created = false;
213
+ const filled = [];
214
+ let entry;
215
+ if (list === undefined || list === null || (isScalar(list) && (list.value === null || list.value === undefined))) {
216
+ created = true;
217
+ entry = input.entry;
218
+ const seq = doc.createNode([]);
219
+ seq.items.push(entryNode(doc, entry));
220
+ // `foundations: # a note` keeps its note when the list is written.
221
+ if (isScalar(list) && list.comment)
222
+ seq.comment = list.comment;
223
+ doc.set("foundations", seq);
224
+ }
225
+ else if (!isSeq(list)) {
226
+ throw new FoundationError("foundation_manifest_conflict", `foundations in ${input.episodeYamlPath} is not a list — refusing to overwrite`);
227
+ }
228
+ else {
229
+ const index = list.items.findIndex((item) => sameEntry(toEpisodeFoundationEntry(isMap(item) ? item.toJSON() : item?.value ?? item), input.entry));
230
+ if (index < 0) {
231
+ created = true;
232
+ entry = input.entry;
233
+ list.items.push(entryNode(doc, entry));
234
+ }
235
+ else {
236
+ const item = list.items[index];
237
+ if (!isMap(item)) {
238
+ // `- lattice` written by hand already holds the packet. It is left
239
+ // as written: held, nothing to fill (#713 review, F7).
240
+ entry = toEpisodeFoundationEntry(isScalar(item) ? item.value : item) ?? input.entry;
241
+ }
242
+ else {
243
+ for (const key of FOUNDATION_ENTRY_KEYS) {
244
+ const value = input.entry[key];
245
+ if (value === undefined || value === "")
246
+ continue;
247
+ const present = item.get(key);
248
+ if (present === undefined || present === null || present === "") {
249
+ item.set(key, quoted(doc, value));
250
+ filled.push(key);
251
+ }
252
+ }
253
+ entry = toEpisodeFoundationEntry(item.toJSON()) ?? input.entry;
254
+ }
255
+ }
256
+ }
257
+ const wrote = (created || filled.length > 0) && !input.dryRun;
258
+ if (wrote)
259
+ await writeFile(input.episodeYamlPath, doc.toString(), "utf8");
260
+ return { entry, created, filled, wrote, dryRun: input.dryRun === true };
261
+ }
262
+ /**
263
+ * The relationship type of an episode→foundation edge already on the wheel.
264
+ * Never throws: an unreadable wheel answers undefined.
265
+ */
266
+ export async function existingFoundationRelation(mwUrl, episodeNodeId, nodeId, options = {}) {
267
+ const listing = await wheelJson(options.fetchImpl ?? fetch, `${mwUrl.replace(/\/+$/, "")}/api/edges?limit=all`);
268
+ if (!listing.ok)
269
+ return undefined;
270
+ const edge = edgesFrom(listing.body).find((e) => String(e.from_id) === episodeNodeId && String(e.to_id) === nodeId);
271
+ return typeof edge?.relationship_type === "string" && edge.relationship_type ? edge.relationship_type : undefined;
272
+ }
273
+ /**
274
+ * Put the foundation node and the episode→foundation edge on the wheel. A
275
+ * packet is a `knowledge` node, which the wheel's ontology already carries.
276
+ * When the node exists, only `metadata.version` is refreshed, so a
277
+ * hand-written name and description stay.
278
+ */
279
+ export async function projectEpisodeFoundation(mwUrl, input, options = {}) {
280
+ const fetchImpl = options.fetchImpl ?? fetch;
281
+ const base = mwUrl.replace(/\/+$/, "");
282
+ const nodeId = foundationNodeId(input.packet.slug, input.source === "episode" ? input.episodeFolder : undefined);
283
+ const edgeId = `${input.episodeNodeId}:${nodeId}`;
284
+ const projection = {
285
+ node: { id: nodeId, state: "pending" },
286
+ edge: { id: edgeId, state: "pending", relationship_type: input.relation },
287
+ };
288
+ const nodeUrl = `${base}/api/nodes/${encodeURIComponent(nodeId)}`;
289
+ const read = await wheelJson(fetchImpl, nodeUrl);
290
+ if (read.ok) {
291
+ const node = read.body?.node;
292
+ if (input.packet.version === undefined || node?.metadata?.version === input.packet.version) {
293
+ projection.node.state = "already-present";
294
+ }
295
+ else if (options.dryRun) {
296
+ projection.node.state = "skipped";
297
+ }
298
+ else {
299
+ const patched = await wheelJson(fetchImpl, nodeUrl, {
300
+ method: "PATCH",
301
+ headers: { "content-type": "application/json" },
302
+ body: JSON.stringify({ metadata: { version: input.packet.version } }),
303
+ });
304
+ projection.node = patched.ok ? { id: nodeId, state: "refreshed" } : { id: nodeId, state: "pending", error: failure("PATCH", nodeUrl, patched) };
305
+ }
306
+ }
307
+ else if (read.status === 404) {
308
+ if (options.dryRun) {
309
+ projection.node.state = "skipped";
310
+ }
311
+ else {
312
+ const own = input.source === "episode";
313
+ const created = await wheelJson(fetchImpl, `${base}/api/nodes`, {
314
+ method: "POST",
315
+ headers: { "content-type": "application/json" },
316
+ body: JSON.stringify({
317
+ id: nodeId,
318
+ type: "knowledge",
319
+ name: `Foundation — ${input.packet.title}`,
320
+ description: own
321
+ ? `A foundation packet written inside episode ${input.episodeFolder}: ${input.packet.title}.`
322
+ : `A Miadi foundation packet (academic grounding): ${input.packet.title}.`,
323
+ direction: "north",
324
+ metadata: {
325
+ kind: FOUNDATION_NODE_KIND,
326
+ slug: input.packet.slug,
327
+ source: input.source,
328
+ ...(input.packet.version ? { version: input.packet.version } : {}),
329
+ ...(input.packet.fields?.length ? { fields: input.packet.fields } : {}),
330
+ ...(input.packet.url ? { public_url: input.packet.url } : {}),
331
+ ...(own ? { episode_path: input.episodeFolder, path: episodeFoundationPath(input.packet.slug) } : { address: `miadi-foundation:${input.packet.slug}` }),
332
+ },
333
+ }),
334
+ });
335
+ projection.node = created.ok ? { id: nodeId, state: "created" } : { id: nodeId, state: "pending", error: failure("POST", `${base}/api/nodes`, created) };
336
+ }
337
+ }
338
+ else {
339
+ projection.node = { id: nodeId, state: "pending", error: failure("GET", nodeUrl, read) };
340
+ }
341
+ // An edge to a node the wheel does not hold would dangle; wait for the node.
342
+ if (projection.node.state === "pending") {
343
+ projection.edge.error = "the foundation node is not on the wheel yet";
344
+ return projection;
345
+ }
346
+ const edgesUrl = `${base}/api/edges`;
347
+ // POST replaces a pair the wheel already holds: read the whole list first,
348
+ // so an edge someone wrote by hand is never overwritten.
349
+ const listing = await wheelJson(fetchImpl, `${edgesUrl}?limit=all`);
350
+ if (!listing.ok) {
351
+ projection.edge.error = failure("GET", edgesUrl, listing);
352
+ return projection;
353
+ }
354
+ const existing = edgesFrom(listing.body).find((edge) => String(edge.from_id) === input.episodeNodeId && String(edge.to_id) === nodeId);
355
+ if (existing) {
356
+ projection.edge = { id: edgeId, state: "already-present", relationship_type: String(existing.relationship_type ?? input.relation) };
357
+ return projection;
358
+ }
359
+ if (options.dryRun) {
360
+ projection.edge.state = "skipped";
361
+ return projection;
362
+ }
363
+ const posted = await wheelJson(fetchImpl, edgesUrl, {
364
+ method: "POST",
365
+ headers: { "content-type": "application/json" },
366
+ body: JSON.stringify({ from_id: input.episodeNodeId, to_id: nodeId, relationship_type: input.relation, strength: 1, obligations: [] }),
367
+ });
368
+ if (posted.ok && posted.body?.replaced === true) {
369
+ projection.edge = { id: edgeId, state: "pending", relationship_type: input.relation, error: "the wheel replaced an edge the listing did not show; check the edge by hand" };
370
+ }
371
+ else if (posted.ok)
372
+ projection.edge.state = "created";
373
+ else if (posted.status === 409)
374
+ projection.edge.state = "already-present";
375
+ else
376
+ projection.edge.error = failure("POST", edgesUrl, posted);
377
+ return projection;
378
+ }
379
+ export { DEFAULT_FOUNDATION_RELATION };
380
+ //# sourceMappingURL=foundation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foundation.js","sourceRoot":"","sources":["../src/foundation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAA+B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AAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,6EAA6E,EAAE,CAAA;IAC7K,CAAC;SAAM,IAAI,MAAM,CAAC,EAAE;QAAE,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;SAClD,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;QAAE,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,iBAAiB,CAAA;;QACpE,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC9D,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAA"}
package/dist/index.d.ts CHANGED
@@ -19,6 +19,9 @@ export * from "./catalog.js";
19
19
  export * from "./readings.js";
20
20
  export * from "./text-references.js";
21
21
  export * from "./chronicle-dsl.js";
22
+ export * from "./foundation-dsl.js";
23
+ export * from "./markdown-directives.js";
24
+ export * from "./foundation.js";
22
25
  export * from "./chronicle-terminal.js";
23
26
  export * from "./story-library.js";
24
27
  export * from "./git-landing.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe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index.js CHANGED
@@ -19,6 +19,9 @@ export * from "./catalog.js";
19
19
  export * from "./readings.js";
20
20
  export * from "./text-references.js";
21
21
  export * from "./chronicle-dsl.js";
22
+ export * from "./foundation-dsl.js";
23
+ export * from "./markdown-directives.js";
24
+ export * from "./foundation.js";
22
25
  export * from "./chronicle-terminal.js";
23
26
  export * from "./story-library.js";
24
27
  export * from "./git-landing.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,MAAM,EAAuC,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,MAAM,EAAuC,MAAM,UAAU,CAAA"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The markdown pass every renderer of chronicle text runs before its markdown
3
+ * parser: `{{ … }}` directives become standard links, so one link renderer
4
+ * serves the link form and the directive form alike (SPEC §3, single-channel
5
+ * fold-in). Plus the text-level hints a page uses to load what references
6
+ * name before it renders, and the ceremony-prefix completion an editor runs
7
+ * on save (SPEC §9.2).
8
+ *
9
+ * Moved here from the Miadi app (`app/chronicle/lib/dsl.ts`) so the app and
10
+ * any other host (the review service, a v0 page) run one copy
11
+ * (jgwill/Miadi#713). Every bound and every guard below was earned in a
12
+ * review of the app's copy; the references are kept with them.
13
+ *
14
+ * Pure — no fs, no fetch, no React.
15
+ */
16
+ import { type ParsedWheelRef } from "./chronicle-dsl.js";
17
+ export interface DirectiveMatch {
18
+ /** The whole `{{ … }}` source text. */
19
+ raw: string;
20
+ uri: string;
21
+ options: Record<string, string>;
22
+ }
23
+ /** Find every chronicle directive in a text without altering it. */
24
+ export declare function findDirectives(text: string): DirectiveMatch[];
25
+ /**
26
+ * Markdown pre-pass: rewrite each `{{ uri | opts }}` directive into a
27
+ * standard markdown link, folding options into the URI as mc.* params:
28
+ * {{ miadi-chronicle:126 | show=card, label="Mila" }}
29
+ * → [Mila](miadi-chronicle:126?mc.show=card&mc.label=Mila)
30
+ * {{ foundation:lattice }}
31
+ * → [lattice](miadi-foundation:lattice)
32
+ * Invalid URIs, and directives inside code fences or inline code spans, are
33
+ * left as literal text (graceful degradation).
34
+ */
35
+ export declare function transformDirectives(markdown: string): string;
36
+ /**
37
+ * Collect chronicle references for embedding/metadata consumers. Covers the
38
+ * directive form, inline links `[t](uri)`, and autolinks `<uri>`. It is a
39
+ * text-level HINT, not the render path: reference-style links and character
40
+ * references need a real markdown parse, which a renderer does — rendering
41
+ * resolves from the AST-provided href, never from this list.
42
+ */
43
+ export declare function extractChronicleUris(markdown: string): string[];
44
+ /**
45
+ * Collect wheel references so a page can load what they name before it
46
+ * renders. Every href the markdown parser can hand the link override contains
47
+ * the scheme and the id as text, so the whole text is scanned rather than
48
+ * link syntax: a title after the destination, a definition inside a
49
+ * blockquote or a destination on the next line all count (jgwill/Miadi#680
50
+ * review, F3). Directives are expanded first so short forms are found. A hint
51
+ * that errs wide: an extra id loads a view no link asks for.
52
+ */
53
+ export declare function extractWheelRefs(markdown: string): ParsedWheelRef[];
54
+ /**
55
+ * The packet slugs a text names, directives expanded first, so a page can
56
+ * read each packet's title once before it renders. Errs wide, like
57
+ * extractWheelRefs: an extra slug costs one lookup.
58
+ */
59
+ export declare function extractFoundationSlugs(markdown: string): string[];
60
+ /**
61
+ * Complete ceremony UUID prefixes to full ids: what an article editor does
62
+ * on save (SPEC §9.2). A prefix that names one ceremony today can match two
63
+ * tomorrow, so the kept text carries the whole id. `resolve` answers a prefix
64
+ * with the one id it names, or null. Only ceremony references outside code
65
+ * are touched; a full UUID never matches (8 to 35 characters only).
66
+ */
67
+ export declare function expandCeremonyPrefixes(markdown: string, resolve: (prefix: string) => string | null): {
68
+ text: string;
69
+ expanded: number;
70
+ };
71
+ export declare function linkBareReferences(markdown: string): string;
72
+ //# sourceMappingURL=markdown-directives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown-directives.d.ts","sourceRoot":"","sources":["../src/markdown-directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAKL,KAAK,cAAc,EAEpB,MAAM,oBAAoB,CAAA;AA2B3B,MAAM,WAAW,cAAc;IAC7B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAcD,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAM7D;AA4DD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAM/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAWnE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAUjE;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACzC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAoBpC;AAsBD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA6B3D"}