structured-context 0.10.0 → 0.12.0
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/README.md +85 -25
- package/dist/api.d.ts +25 -5
- package/dist/api.js +22 -2
- package/dist/commands/diagram.d.ts +1 -0
- package/dist/commands/diagram.js +7 -1
- package/dist/commands/dump.d.ts +15 -2
- package/dist/commands/dump.js +18 -4
- package/dist/commands/miro-sync.d.ts +3 -0
- package/dist/commands/miro-sync.js +8 -0
- package/dist/commands/render.d.ts +4 -0
- package/dist/commands/render.js +64 -9
- package/dist/commands/schemas.d.ts +2 -2
- package/dist/commands/schemas.js +117 -24
- package/dist/commands/show.d.ts +1 -0
- package/dist/commands/show.js +7 -1
- package/dist/commands/spaces.d.ts +3 -1
- package/dist/commands/spaces.js +11 -4
- package/dist/commands/validate-file.js +20 -5
- package/dist/commands/validate.js +54 -21
- package/dist/config.d.ts +26 -13
- package/dist/config.js +104 -31
- package/dist/filter/augment-nodes.d.ts +3 -1
- package/dist/filter/augment-nodes.js +12 -7
- package/dist/filter/filter-nodes.js +1 -1
- package/dist/index.js +51 -35
- package/dist/load-space-graph.d.ts +42 -0
- package/dist/load-space-graph.js +53 -0
- package/dist/plugins/index.js +3 -1
- package/dist/plugins/loader.js +4 -4
- package/dist/plugins/markdown/extract-content-links.d.ts +23 -0
- package/dist/plugins/markdown/extract-content-links.js +123 -0
- package/dist/plugins/markdown/index.js +5 -5
- package/dist/plugins/markdown/parse-embedded.d.ts +6 -0
- package/dist/plugins/markdown/parse-embedded.js +50 -7
- package/dist/plugins/markdown/read-space.js +41 -5
- package/dist/plugins/markdown/render-directory.d.ts +11 -0
- package/dist/plugins/markdown/render-directory.js +130 -0
- package/dist/plugins/mermaid/index.d.ts +2 -0
- package/dist/plugins/mermaid/index.js +14 -0
- package/dist/plugins/{markdown → mermaid}/render-mermaid.js +17 -15
- package/dist/{integrations → plugins}/miro/cache.d.ts +1 -1
- package/dist/plugins/miro/index.d.ts +2 -0
- package/dist/plugins/miro/index.js +27 -0
- package/dist/{integrations → plugins}/miro/layout.d.ts +2 -2
- package/dist/{integrations → plugins}/miro/layout.js +3 -16
- package/dist/{integrations → plugins}/miro/styles.d.ts +2 -2
- package/dist/plugins/miro/sync.d.ts +7 -0
- package/dist/{integrations → plugins}/miro/sync.js +22 -39
- package/dist/plugins/util.d.ts +48 -1
- package/dist/plugins/util.js +143 -0
- package/dist/read/resolve-graph-edges.d.ts +1 -1
- package/dist/read/resolve-graph-edges.js +78 -27
- package/dist/read/wikilink-utils.d.ts +17 -0
- package/dist/read/wikilink-utils.js +40 -0
- package/dist/render/render.d.ts +4 -1
- package/dist/render/render.js +20 -16
- package/dist/schema/evaluate-rule.js +1 -0
- package/dist/schema/meta-schemas.d.ts +13 -0
- package/dist/schema/meta-schemas.js +50 -0
- package/dist/schema/metadata-contract.d.ts +343 -187
- package/dist/schema/metadata-contract.js +68 -30
- package/dist/schema/schema.d.ts +17 -9
- package/dist/schema/schema.js +283 -200
- package/dist/schema/validate-graph.d.ts +2 -1
- package/dist/schema/validate-graph.js +40 -23
- package/dist/schema/validate-rules.d.ts +5 -1
- package/dist/schema/validate-rules.js +20 -1
- package/dist/schemas/_knowledge_wiki.json +21 -21
- package/dist/schemas/_ost_strict.json +2 -2
- package/dist/schemas/_sctx_base.json +2 -2
- package/dist/schemas/_strategy_general.json +38 -38
- package/dist/schemas/generated/0.12.0/_structured_context_schema_meta.json +229 -0
- package/dist/schemas/generated/latest/_structured_context_schema_meta.json +229 -0
- package/dist/schemas/knowledge_wiki.json +10 -9
- package/dist/schemas/strategy_general.json +15 -14
- package/dist/schemas/strict_ost.json +17 -16
- package/dist/space-context.d.ts +27 -0
- package/dist/space-context.js +46 -0
- package/dist/space-graph.d.ts +9 -7
- package/dist/space-graph.js +7 -5
- package/dist/testing.d.ts +33 -0
- package/dist/testing.js +72 -0
- package/dist/types.d.ts +101 -8
- package/dist/validate.d.ts +15 -3
- package/dist/validate.js +55 -20
- package/docs/concepts.md +37 -4
- package/docs/config.md +10 -0
- package/docs/rules.md +49 -22
- package/docs/schemas.md +110 -35
- package/package.json +13 -8
- package/schemas/_knowledge_wiki.json +21 -21
- package/schemas/_ost_strict.json +2 -2
- package/schemas/_sctx_base.json +2 -2
- package/schemas/_strategy_general.json +38 -38
- package/schemas/generated/0.12.0/_structured_context_schema_meta.json +229 -0
- package/schemas/generated/latest/_structured_context_schema_meta.json +229 -0
- package/schemas/knowledge_wiki.json +10 -9
- package/schemas/strategy_general.json +15 -14
- package/schemas/strict_ost.json +17 -16
- package/dist/integrations/miro/sync.d.ts +0 -8
- package/dist/schemas/generated/_structured_context_schema_meta.json +0 -191
- package/schemas/generated/_structured_context_schema_meta.json +0 -191
- /package/dist/plugins/{markdown → mermaid}/render-mermaid.d.ts +0 -0
- /package/dist/{integrations → plugins}/miro/cache.js +0 -0
- /package/dist/{integrations → plugins}/miro/client.d.ts +0 -0
- /package/dist/{integrations → plugins}/miro/client.js +0 -0
- /package/dist/{integrations → plugins}/miro/styles.js +0 -0
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a wikilink string.
|
|
3
|
+
* formatWikilink('My Goal') -> '[[My Goal]]'
|
|
4
|
+
* formatWikilink('My Goal', 'Custom Display') -> '[[My Goal|Custom Display]]'
|
|
5
|
+
*/
|
|
6
|
+
export function formatWikilink(target, alias) {
|
|
7
|
+
const trimmedTarget = target.trim();
|
|
8
|
+
const trimmedAlias = alias?.trim();
|
|
9
|
+
if (trimmedAlias && trimmedAlias !== trimmedTarget) {
|
|
10
|
+
return `[[${trimmedTarget}|${trimmedAlias}]]`;
|
|
11
|
+
}
|
|
12
|
+
return `[[${trimmedTarget}]]`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse a wikilink or link inner string into target, anchor, and displayText.
|
|
16
|
+
* Handles: [[target]], [[target#anchor]], [[target|alias]], [[target#anchor|alias]]
|
|
17
|
+
* Also handles bare forms without enclosing brackets.
|
|
18
|
+
*/
|
|
19
|
+
export function parseWikilink(wikilink) {
|
|
20
|
+
const cleaned = wikilink.replace(/^"|"$/g, '').trim();
|
|
21
|
+
const inner = cleaned.startsWith('[[') && cleaned.endsWith(']]') ? cleaned.slice(2, -2).trim() : cleaned;
|
|
22
|
+
// Alias: [[target|alias]] or [[target#anchor|alias]]
|
|
23
|
+
const pipeIdx = inner.indexOf('|');
|
|
24
|
+
let core = inner;
|
|
25
|
+
let displayText;
|
|
26
|
+
if (pipeIdx >= 0) {
|
|
27
|
+
core = inner.slice(0, pipeIdx);
|
|
28
|
+
const alias = inner.slice(pipeIdx + 1).trim();
|
|
29
|
+
if (alias)
|
|
30
|
+
displayText = alias;
|
|
31
|
+
}
|
|
32
|
+
// Anchor: [[target#anchor]] or [[target#^block]]
|
|
33
|
+
const hashIdx = core.indexOf('#');
|
|
34
|
+
if (hashIdx >= 0) {
|
|
35
|
+
const target = core.slice(0, hashIdx).trim();
|
|
36
|
+
const anchor = core.slice(hashIdx + 1).trim() || undefined;
|
|
37
|
+
return { target, anchor, displayText };
|
|
38
|
+
}
|
|
39
|
+
return { target: core.trim(), displayText };
|
|
40
|
+
}
|
|
1
41
|
/**
|
|
2
42
|
* Extract the lookup key from a wikilink string such as:
|
|
3
43
|
* [[Personal Vision]] → "Personal Vision"
|
package/dist/render/render.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { type RenderResult } from '../plugins/util';
|
|
1
2
|
import type { SpaceContext } from '../types';
|
|
2
3
|
export declare function executeRender(formatName: string, context: SpaceContext, options: {
|
|
3
4
|
filter?: string;
|
|
4
|
-
|
|
5
|
+
hierarchy?: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
}): Promise<RenderResult>;
|
package/dist/render/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shortenPluginName } from '../plugins/util';
|
|
2
|
+
import { updateSpaceField } from '../config';
|
|
3
|
+
import { assembleSpaceGraph } from '../load-space-graph';
|
|
2
4
|
import { loadPlugins } from '../plugins/loader';
|
|
3
|
-
import { readSpace } from '../read/read-space';
|
|
4
|
-
import { buildSpaceGraph } from '../space-graph';
|
|
5
5
|
import { buildFormatRegistry } from './registry';
|
|
6
6
|
export async function executeRender(formatName, context, options) {
|
|
7
7
|
const pluginMap = context.space?.plugins ?? {};
|
|
@@ -12,17 +12,21 @@ export async function executeRender(formatName, context, options) {
|
|
|
12
12
|
const available = registry.map((r) => r.qualifiedName).join(', ');
|
|
13
13
|
throw new Error(`Unknown render format: "${formatName}".${available ? ` Available: ${available}` : ' No formats registered.'}`);
|
|
14
14
|
}
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const graph = await assembleSpaceGraph(context, { filter: options.filter, hierarchy: options.hierarchy });
|
|
16
|
+
const shortName = shortenPluginName(entry.plugin.plugin.name);
|
|
17
|
+
const pluginContext = {
|
|
18
|
+
...context,
|
|
19
|
+
pluginConfig: entry.plugin.pluginConfig,
|
|
20
|
+
callbacks: {
|
|
21
|
+
persistConfig: (updates) => {
|
|
22
|
+
for (const [field, value] of Object.entries(updates)) {
|
|
23
|
+
updateSpaceField(context.space.name, field, value, shortName);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
return entry.plugin.plugin.render.render(pluginContext, graph, {
|
|
29
|
+
format: entry.format.name,
|
|
30
|
+
data: options.data,
|
|
31
|
+
});
|
|
28
32
|
}
|
|
@@ -52,6 +52,7 @@ function flattenNode(node) {
|
|
|
52
52
|
resolvedType: node.resolvedType,
|
|
53
53
|
resolvedParentTitle: node.resolvedParents[0]?.title, // first parent or undefined, provided for convenience
|
|
54
54
|
resolvedParentTitles: node.resolvedParents.map((r) => r.title), // full array of parent titles
|
|
55
|
+
resolvedLinks: node.resolvedLinks,
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AnySchemaObject } from 'ajv';
|
|
2
|
+
/** Version folders under `generatedDir` (named after the release that first shipped the dialect), oldest first. */
|
|
3
|
+
export declare function listMetaVersions(generatedDir: string): string[];
|
|
4
|
+
/** The newest released meta-schema and its version folder, if any. */
|
|
5
|
+
export declare function readNewestMetaSchema(generatedDir: string): {
|
|
6
|
+
version: string;
|
|
7
|
+
schema: AnySchemaObject;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Meta-schemas shipped in `<schemasDir>/generated/`, keyed by `$id`: every versioned folder at its own `$id`, and
|
|
11
|
+
* `latest` registered under the `latest` URL so `$schema` references to either form resolve.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadMetaSchemas(schemasDir: string): Map<string, AnySchemaObject>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { SCHEMA_META_FILE, SCHEMA_META_ID } from './metadata-contract';
|
|
4
|
+
const LATEST_FOLDER = 'latest';
|
|
5
|
+
const VERSION_FOLDER = /^\d+\.\d+\.\d+$/;
|
|
6
|
+
function compareVersions(a, b) {
|
|
7
|
+
const [pa, pb] = [a, b].map((v) => v.split('.').map(Number));
|
|
8
|
+
for (let i = 0; i < 3; i++) {
|
|
9
|
+
const diff = (pa?.[i] ?? 0) - (pb?.[i] ?? 0);
|
|
10
|
+
if (diff !== 0)
|
|
11
|
+
return diff;
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
/** Version folders under `generatedDir` (named after the release that first shipped the dialect), oldest first. */
|
|
16
|
+
export function listMetaVersions(generatedDir) {
|
|
17
|
+
if (!existsSync(generatedDir))
|
|
18
|
+
return [];
|
|
19
|
+
return readdirSync(generatedDir)
|
|
20
|
+
.filter((name) => VERSION_FOLDER.test(name))
|
|
21
|
+
.sort(compareVersions);
|
|
22
|
+
}
|
|
23
|
+
function readMetaSchema(generatedDir, folder) {
|
|
24
|
+
const path = join(generatedDir, folder, SCHEMA_META_FILE);
|
|
25
|
+
return existsSync(path) ? JSON.parse(readFileSync(path, 'utf-8')) : undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The newest released meta-schema and its version folder, if any. */
|
|
28
|
+
export function readNewestMetaSchema(generatedDir) {
|
|
29
|
+
const version = listMetaVersions(generatedDir).at(-1);
|
|
30
|
+
const schema = version && readMetaSchema(generatedDir, version);
|
|
31
|
+
return version && schema ? { version, schema } : undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Meta-schemas shipped in `<schemasDir>/generated/`, keyed by `$id`: every versioned folder at its own `$id`, and
|
|
35
|
+
* `latest` registered under the `latest` URL so `$schema` references to either form resolve.
|
|
36
|
+
*/
|
|
37
|
+
export function loadMetaSchemas(schemasDir) {
|
|
38
|
+
const generatedDir = join(schemasDir, 'generated');
|
|
39
|
+
const schemas = new Map();
|
|
40
|
+
for (const version of listMetaVersions(generatedDir)) {
|
|
41
|
+
const schema = readMetaSchema(generatedDir, version);
|
|
42
|
+
if (schema && typeof schema.$id === 'string')
|
|
43
|
+
schemas.set(schema.$id, schema);
|
|
44
|
+
}
|
|
45
|
+
// The `latest` copy carries its versioned `$id`, which a version folder may already own; register it under its own URL.
|
|
46
|
+
const latest = readMetaSchema(generatedDir, LATEST_FOLDER);
|
|
47
|
+
if (latest)
|
|
48
|
+
schemas.set(SCHEMA_META_ID, { ...latest, $id: SCHEMA_META_ID });
|
|
49
|
+
return schemas;
|
|
50
|
+
}
|