structured-context 0.11.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.
Files changed (87) hide show
  1. package/README.md +63 -22
  2. package/dist/api.d.ts +7 -5
  3. package/dist/api.js +4 -1
  4. package/dist/commands/diagram.d.ts +1 -0
  5. package/dist/commands/diagram.js +7 -1
  6. package/dist/commands/dump.d.ts +15 -2
  7. package/dist/commands/dump.js +18 -4
  8. package/dist/commands/render.d.ts +4 -0
  9. package/dist/commands/render.js +64 -9
  10. package/dist/commands/schemas.d.ts +2 -2
  11. package/dist/commands/schemas.js +114 -22
  12. package/dist/commands/show.d.ts +1 -0
  13. package/dist/commands/show.js +7 -1
  14. package/dist/commands/spaces.d.ts +3 -1
  15. package/dist/commands/spaces.js +11 -2
  16. package/dist/commands/validate-file.js +7 -4
  17. package/dist/commands/validate.js +38 -21
  18. package/dist/config.d.ts +18 -1
  19. package/dist/config.js +81 -10
  20. package/dist/filter/augment-nodes.d.ts +3 -1
  21. package/dist/filter/augment-nodes.js +12 -7
  22. package/dist/filter/filter-nodes.js +1 -1
  23. package/dist/index.js +39 -15
  24. package/dist/load-space-graph.d.ts +4 -2
  25. package/dist/load-space-graph.js +15 -4
  26. package/dist/plugins/loader.js +2 -2
  27. package/dist/plugins/markdown/extract-content-links.js +8 -29
  28. package/dist/plugins/markdown/index.js +8 -2
  29. package/dist/plugins/markdown/parse-embedded.d.ts +6 -0
  30. package/dist/plugins/markdown/parse-embedded.js +41 -7
  31. package/dist/plugins/markdown/read-space.js +38 -5
  32. package/dist/plugins/markdown/render-directory.d.ts +11 -0
  33. package/dist/plugins/markdown/render-directory.js +130 -0
  34. package/dist/plugins/mermaid/render-mermaid.js +2 -1
  35. package/dist/plugins/miro/sync.js +7 -6
  36. package/dist/plugins/util.d.ts +39 -1
  37. package/dist/plugins/util.js +139 -0
  38. package/dist/read/resolve-graph-edges.d.ts +1 -1
  39. package/dist/read/resolve-graph-edges.js +46 -27
  40. package/dist/read/wikilink-utils.d.ts +17 -0
  41. package/dist/read/wikilink-utils.js +40 -0
  42. package/dist/render/render.d.ts +3 -1
  43. package/dist/render/render.js +2 -2
  44. package/dist/schema/meta-schemas.d.ts +13 -0
  45. package/dist/schema/meta-schemas.js +50 -0
  46. package/dist/schema/metadata-contract.d.ts +343 -187
  47. package/dist/schema/metadata-contract.js +68 -30
  48. package/dist/schema/schema.d.ts +14 -8
  49. package/dist/schema/schema.js +277 -198
  50. package/dist/schema/validate-graph.d.ts +2 -1
  51. package/dist/schema/validate-graph.js +40 -23
  52. package/dist/schema/validate-rules.d.ts +5 -1
  53. package/dist/schema/validate-rules.js +20 -1
  54. package/dist/schemas/_knowledge_wiki.json +20 -20
  55. package/dist/schemas/_ost_strict.json +2 -2
  56. package/dist/schemas/_sctx_base.json +2 -2
  57. package/dist/schemas/_strategy_general.json +38 -38
  58. package/dist/schemas/generated/0.12.0/_structured_context_schema_meta.json +229 -0
  59. package/dist/schemas/generated/latest/_structured_context_schema_meta.json +229 -0
  60. package/dist/schemas/knowledge_wiki.json +10 -9
  61. package/dist/schemas/strategy_general.json +15 -14
  62. package/dist/schemas/strict_ost.json +17 -16
  63. package/dist/space-context.d.ts +3 -0
  64. package/dist/space-context.js +7 -2
  65. package/dist/space-graph.d.ts +9 -7
  66. package/dist/space-graph.js +7 -5
  67. package/dist/testing.d.ts +33 -0
  68. package/dist/testing.js +72 -0
  69. package/dist/types.d.ts +54 -13
  70. package/dist/validate.d.ts +3 -0
  71. package/dist/validate.js +19 -9
  72. package/docs/concepts.md +14 -4
  73. package/docs/config.md +8 -0
  74. package/docs/rules.md +49 -22
  75. package/docs/schemas.md +110 -35
  76. package/package.json +13 -8
  77. package/schemas/_knowledge_wiki.json +20 -20
  78. package/schemas/_ost_strict.json +2 -2
  79. package/schemas/_sctx_base.json +2 -2
  80. package/schemas/_strategy_general.json +38 -38
  81. package/schemas/generated/0.12.0/_structured_context_schema_meta.json +229 -0
  82. package/schemas/generated/latest/_structured_context_schema_meta.json +229 -0
  83. package/schemas/knowledge_wiki.json +10 -9
  84. package/schemas/strategy_general.json +15 -14
  85. package/schemas/strict_ost.json +17 -16
  86. package/dist/schemas/generated/_structured_context_schema_meta.json +0 -191
  87. package/schemas/generated/_structured_context_schema_meta.json +0 -191
@@ -1,4 +1,13 @@
1
- export const SCHEMA_META_ID = 'https://raw.githubusercontent.com/mindsocket/structured-context/main/schemas/generated/_structured_context_schema_meta.json';
1
+ /** The JSON Schema dialect the structured-context dialect extends. */
2
+ export const JSON_SCHEMA_DIALECT = 'https://json-schema.org/draft/2020-12/schema';
3
+ export const SCHEMA_META_BASE_URL = 'https://raw.githubusercontent.com/mindsocket/structured-context/main/schemas/generated';
4
+ export const SCHEMA_META_FILE = '_structured_context_schema_meta.json';
5
+ /** Meta-schema `$id` for a dialect version folder, e.g. `.../generated/0.12.0/_structured_context_schema_meta.json`. */
6
+ export function schemaMetaId(folder) {
7
+ return `${SCHEMA_META_BASE_URL}/${folder}/${SCHEMA_META_FILE}`;
8
+ }
9
+ /** The URL schemas set as `$schema` to follow the newest dialect. Resolves to the newest versioned meta-schema. */
10
+ export const SCHEMA_META_ID = schemaMetaId('latest');
2
11
  /** Graph edge routing fields shared by hierarchy levels and relationships. */
3
12
  const EDGE_PROPS = {
4
13
  field: { type: 'string', minLength: 1 },
@@ -39,6 +48,7 @@ const RULE_SCHEMA = {
39
48
  properties: {
40
49
  id: { type: 'string', minLength: 1 },
41
50
  category: { enum: ['validation', 'coherence', 'workflow', 'best-practice'] },
51
+ severity: { enum: ['error', 'warning', 'info'] },
42
52
  description: { type: 'string', minLength: 1 },
43
53
  check: { type: 'string', minLength: 1 },
44
54
  type: { type: 'string', minLength: 1 },
@@ -48,7 +58,7 @@ const RULE_SCHEMA = {
48
58
  required: ['id', 'category', 'description', 'check'],
49
59
  additionalProperties: false,
50
60
  };
51
- const RULE_REF_SCHEMA = {
61
+ const REF_SCHEMA = {
52
62
  type: 'object',
53
63
  properties: {
54
64
  $ref: { type: 'string', minLength: 1 },
@@ -56,6 +66,23 @@ const RULE_REF_SCHEMA = {
56
66
  required: ['$ref'],
57
67
  additionalProperties: false,
58
68
  };
69
+ const HIERARCHY_SCHEMA = {
70
+ type: 'object',
71
+ properties: {
72
+ name: { type: 'string', minLength: 1 },
73
+ override: { type: 'boolean' },
74
+ levels: {
75
+ type: 'array',
76
+ minItems: 1,
77
+ items: {
78
+ oneOf: [{ type: 'string', minLength: 1 }, HIERARCHY_LEVEL_SCHEMA],
79
+ },
80
+ },
81
+ allowSkipLevels: { type: 'boolean' },
82
+ },
83
+ required: ['levels'],
84
+ additionalProperties: false,
85
+ };
59
86
  const RELATIONSHIP_SCHEMA = {
60
87
  type: 'object',
61
88
  properties: {
@@ -63,53 +90,64 @@ const RELATIONSHIP_SCHEMA = {
63
90
  type: { type: 'string', minLength: 1 },
64
91
  ...EDGE_PROPS,
65
92
  ...EMBEDDING_PROPS,
93
+ override: { type: 'boolean' },
66
94
  },
67
95
  required: ['parent', 'type'],
68
96
  additionalProperties: false,
69
97
  };
70
- export const METADATA_SCHEMA = {
71
- type: 'object',
72
- properties: {
73
- hierarchy: {
98
+ /** An alias target: a type name, or `{ type, override: true }` to replace an imported alias. */
99
+ const ALIAS_SCHEMA = {
100
+ oneOf: [
101
+ { type: 'string', minLength: 1 },
102
+ {
74
103
  type: 'object',
75
104
  properties: {
76
- levels: {
77
- type: 'array',
78
- minItems: 1,
79
- items: {
80
- oneOf: [{ type: 'string', minLength: 1 }, HIERARCHY_LEVEL_SCHEMA],
81
- },
82
- },
83
- allowSkipLevels: { type: 'boolean' },
105
+ type: { type: 'string', minLength: 1 },
106
+ override: { type: 'boolean' },
84
107
  },
85
- required: ['levels'],
108
+ required: ['type'],
86
109
  additionalProperties: false,
87
110
  },
111
+ ],
112
+ };
113
+ export const METADATA_SCHEMA = {
114
+ type: 'object',
115
+ properties: {
116
+ // $ids of schemas whose metadata (and their imports' metadata) is merged into this schema's.
117
+ imports: {
118
+ type: 'array',
119
+ items: { type: 'string', minLength: 1 },
120
+ },
121
+ // Either declares this schema's hierarchy, or (root schema only) selects an imported one via $ref.
122
+ hierarchy: {
123
+ oneOf: [HIERARCHY_SCHEMA, REF_SCHEMA],
124
+ },
88
125
  relationships: {
89
126
  type: 'array',
90
127
  items: RELATIONSHIP_SCHEMA,
91
128
  },
92
129
  aliases: {
93
130
  type: 'object',
94
- additionalProperties: { type: 'string', minLength: 1 },
131
+ additionalProperties: ALIAS_SCHEMA,
95
132
  },
96
133
  rules: {
97
134
  type: 'array',
98
- items: {
99
- oneOf: [RULE_SCHEMA, RULE_REF_SCHEMA],
100
- },
135
+ items: RULE_SCHEMA,
101
136
  },
102
137
  },
103
138
  additionalProperties: false,
104
139
  };
105
- export const DIALECT_META_SCHEMA = {
106
- $schema: 'http://json-schema.org/draft-07/schema#',
107
- $id: SCHEMA_META_ID,
108
- title: 'structured-context schema dialect',
109
- description: 'Extends JSON Schema Draft-07 with top-level $metadata for hierarchy and rule metadata.',
110
- type: 'object',
111
- allOf: [{ $ref: 'http://json-schema.org/draft-07/schema#' }],
112
- properties: {
113
- $metadata: METADATA_SCHEMA,
114
- },
115
- };
140
+ /** The dialect meta-schema, published under `$id`. */
141
+ export function buildDialectMetaSchema(id) {
142
+ return {
143
+ $schema: JSON_SCHEMA_DIALECT,
144
+ $id: id,
145
+ title: 'structured-context schema dialect',
146
+ description: 'Extends JSON Schema 2020-12 with top-level $metadata for imports, hierarchy, relationships, aliases and rules.',
147
+ type: 'object',
148
+ allOf: [{ $ref: JSON_SCHEMA_DIALECT }],
149
+ properties: {
150
+ $metadata: METADATA_SCHEMA,
151
+ },
152
+ };
153
+ }
@@ -1,17 +1,23 @@
1
- import { type AnySchemaObject, type ValidateFunction } from 'ajv';
1
+ import type { AnySchemaObject, ValidateFunction } from 'ajv';
2
2
  import type { SchemaMetadata, SchemaWithMetadata } from '../types';
3
3
  export declare let bundledSchemasDir: string;
4
4
  /** Override the bundled schemas directory (e.g. when running in a bundled context). */
5
5
  export declare function setBundledSchemasDir(dir: string): void;
6
6
  export declare function readRawSchema(schemaPath: string): AnySchemaObject;
7
+ export declare const CORE_SCHEMA_PREFIX = "sctx://core/";
8
+ export type PluginSchemaSource = {
9
+ pluginName: string;
10
+ schemasDir: string;
11
+ };
7
12
  /**
8
- * Build the full two-layer registry for a schema path:
13
+ * Build the full multi-layer registry for a schema path:
9
14
  * - Layer 1: bundled schemas/ dir (partials only, as fallback)
10
- * - Layer 2: schema's own dir (partials + target file) — overrides layer 1
11
- * Does not throw on $id collision; layer 2 silently wins.
15
+ * - Layer 2: plugin schema dirs (partials + target file if schemaPath is in this plugin's schemasDir)
16
+ * - Layer 3: schema's own dir (partials + target file)
17
+ * Throws if a lower-precedence schema collides with a reserved $id or violates namespace rules.
12
18
  */
13
- export declare function buildFullRegistry(schemaPath: string): Map<string, AnySchemaObject>;
14
- export declare function createValidator(schemaPath: string): ValidateFunction;
19
+ export declare function buildFullRegistry(schemaPath: string, pluginSchemas?: PluginSchemaSource[]): Map<string, AnySchemaObject>;
20
+ export declare function createValidator(schemaPath: string, pluginSchemas?: PluginSchemaSource[]): ValidateFunction;
15
21
  export declare function resolveNodeType(type: string, typeAliases: Record<string, string> | undefined): string;
16
22
  export interface EntityInfo {
17
23
  type: string;
@@ -20,10 +26,10 @@ export interface EntityInfo {
20
26
  }
21
27
  export declare function extractEntityInfo(schema: SchemaWithMetadata, schemaRefRegistry: Map<string, AnySchemaObject>): EntityInfo[];
22
28
  export declare function extractSchemaTypeNames(schema: SchemaWithMetadata, schemaRefRegistry: Map<string, AnySchemaObject>): Set<string>;
23
- export declare function loadMetadata(schemaPath: string): SchemaMetadata;
29
+ export declare function loadMetadata(schemaPath: string, pluginSchemas?: PluginSchemaSource[]): SchemaMetadata;
24
30
  export interface LoadedSchema {
25
31
  schema: SchemaWithMetadata;
26
32
  schemaRefRegistry: Map<string, AnySchemaObject>;
27
33
  schemaValidator: ValidateFunction;
28
34
  }
29
- export declare function loadSchema(schemaPath: string): LoadedSchema;
35
+ export declare function loadSchema(schemaPath: string, pluginSchemas?: PluginSchemaSource[]): LoadedSchema;