@toolproof-core/schema 1.0.3 → 1.0.5

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 (57) hide show
  1. package/dist/generated/normalized/Genesis.json +16 -265
  2. package/dist/generated/resources/Genesis.json +18 -305
  3. package/dist/generated/schemas/Genesis.json +14 -152
  4. package/dist/generated/schemas/standalone/Goal.json +0 -33
  5. package/dist/generated/schemas/standalone/Job.json +0 -42
  6. package/dist/generated/schemas/standalone/RawStrategy.json +14 -52
  7. package/dist/generated/schemas/standalone/ResourceType.json +0 -34
  8. package/dist/generated/schemas/standalone/RunnableStrategy.json +14 -57
  9. package/dist/generated/schemas/standalone/StrategyRun.json +14 -71
  10. package/dist/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  11. package/dist/generated/types/standalone/Resource_Job.d.ts +1 -1
  12. package/dist/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  13. package/dist/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  14. package/dist/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  15. package/dist/generated/types/types.d.ts +119 -1126
  16. package/dist/index.d.ts +1 -4
  17. package/dist/index.js +0 -2
  18. package/dist/scripts/_lib/config.d.ts +6 -6
  19. package/dist/scripts/_lib/config.js +10 -12
  20. package/dist/scripts/extractSchemasFromResourceTypeShells.js +109 -103
  21. package/dist/scripts/generateDependencies.js +15 -14
  22. package/dist/scripts/generateSchemaShims.js +77 -85
  23. package/dist/scripts/generateStandaloneSchema.js +47 -37
  24. package/dist/scripts/generateStandaloneType.js +85 -79
  25. package/dist/scripts/generateTypes.js +350 -470
  26. package/dist/scripts/normalizeAnchorsToPointers.d.ts +1 -1
  27. package/dist/scripts/normalizeAnchorsToPointers.js +61 -33
  28. package/dist/scripts/wrapResourceTypesWithResourceShells.js +14 -16
  29. package/package.json +7 -8
  30. package/src/Genesis.json +1837 -1999
  31. package/src/generated/{dependencyMap.json → dependencies/dependencyMap.json} +9 -19
  32. package/src/generated/normalized/Genesis.json +16 -265
  33. package/src/generated/resources/Genesis.json +18 -305
  34. package/src/generated/schemas/Genesis.json +14 -152
  35. package/src/generated/schemas/standalone/Goal.json +0 -33
  36. package/src/generated/schemas/standalone/Job.json +0 -42
  37. package/src/generated/schemas/standalone/RawStrategy.json +14 -52
  38. package/src/generated/schemas/standalone/ResourceType.json +0 -34
  39. package/src/generated/schemas/standalone/RunnableStrategy.json +14 -57
  40. package/src/generated/schemas/standalone/StrategyRun.json +14 -71
  41. package/src/generated/types/standalone/Resource_Genesis.d.ts +1 -1
  42. package/src/generated/types/standalone/Resource_Job.d.ts +1 -1
  43. package/src/generated/types/standalone/Resource_RawStrategy.d.ts +1 -1
  44. package/src/generated/types/standalone/Resource_ResourceType.d.ts +1 -1
  45. package/src/generated/types/standalone/Resource_RunnableStrategy.d.ts +1 -1
  46. package/src/generated/types/types.d.ts +119 -1126
  47. package/src/index.ts +66 -93
  48. package/src/scripts/_lib/config.ts +203 -205
  49. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -218
  50. package/src/scripts/generateDependencies.ts +121 -120
  51. package/src/scripts/generateSchemaShims.ts +127 -135
  52. package/src/scripts/generateStandaloneSchema.ts +185 -175
  53. package/src/scripts/generateStandaloneType.ts +127 -119
  54. package/src/scripts/generateTypes.ts +532 -615
  55. package/src/scripts/normalizeAnchorsToPointers.ts +141 -123
  56. package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -84
  57. package/dist/generated/dependencyMap.json +0 -292
@@ -1,123 +1,141 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getConfig } from './_lib/config.js';
4
-
5
- /**
6
- * Rewrite anchor-style references to JSON Pointer references in Genesis.json
7
- *
8
- * Converts #AnchorName to #/$defs/AnchorName for compatibility with strict
9
- * JSON Schema validators and downstream tooling. This normalization step runs
10
- * before both schema extraction and resource envelope generation.
11
- *
12
- * The rewritten file is saved under src/genesis/generated/resourceTypes/Genesis.json
13
- * for use by other scripts.
14
- *
15
- * Usage: node ./dist/scripts/normalizeAnchorsToPointers.js
16
- */
17
-
18
- type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
19
-
20
- /**
21
- * Pure function to rewrite anchor-style references to JSON Pointer references.
22
- * Converts #AnchorName to #/$defs/AnchorName for compatibility with strict JSON Schema validators.
23
- *
24
- * This function works on a schema object that has $defs at its top level.
25
- * @param input The schema object to process
26
- * @returns A new schema object with rewritten references
27
- */
28
- function normalizeAnchorsToPointersToPointers(input: any): any {
29
- if (!input || typeof input !== "object") return input;
30
-
31
- // Deep clone the input to ensure the function is pure (no side effects on input)
32
- const root = JSON.parse(JSON.stringify(input));
33
-
34
- // Build a map of anchors to their definition names
35
- const defs: Record<string, any> = root.$defs && typeof root.$defs === "object" ? root.$defs : {};
36
- const anchorToDef: Record<string, string> = {};
37
-
38
- // For Genesis structure: each def is a Type envelope with nucleusSchema.$anchor
39
- for (const [defName, defValue] of Object.entries(defs)) {
40
- if (!defValue || typeof defValue !== "object") continue;
41
-
42
- // Check if this is a Type envelope (has nucleusSchema property)
43
- const nucleusSchema = (defValue as any).nucleusSchema;
44
- if (nucleusSchema && typeof nucleusSchema === "object") {
45
- // Look for $anchor inside the nucleusSchema
46
- const anchor = nucleusSchema.$anchor;
47
- if (typeof anchor === "string" && !anchorToDef[anchor]) {
48
- anchorToDef[anchor] = defName;
49
- }
50
- } else {
51
- // Fallback: check for $anchor at the def level (non-envelope case)
52
- const anchor = (defValue as any).$anchor;
53
- if (typeof anchor === "string" && !anchorToDef[anchor]) {
54
- anchorToDef[anchor] = defName;
55
- }
56
- }
57
- }
58
-
59
- // Walk the entire tree and rewrite anchor refs to pointer refs
60
- function walk(node: any): void {
61
- if (Array.isArray(node)) {
62
- for (const item of node) walk(item);
63
- return;
64
- }
65
- if (!node || typeof node !== "object") return;
66
-
67
- // Rewrite $ref if it's an anchor-style reference
68
- if (typeof node.$ref === "string") {
69
- const ref: string = node.$ref;
70
- // Match anchor refs: starts with # but not #/ (JSON Pointer syntax)
71
- if (ref.startsWith("#") && !ref.startsWith("#/")) {
72
- const anchor = ref.slice(1);
73
- const defName = anchorToDef[anchor];
74
- if (defName) {
75
- node.$ref = `#/$defs/${defName}`;
76
- }
77
- }
78
- }
79
-
80
- // Recursively walk all properties
81
- for (const val of Object.values(node)) {
82
- walk(val);
83
- }
84
- }
85
-
86
- walk(root);
87
- return root;
88
- }
89
-
90
- async function main() {
91
- const config = getConfig();
92
- const genesisSourcePath = config.getSourcePath();
93
-
94
- // Create a generated/normalized version (anchor refs rewritten to pointers)
95
- const normalizedPath = config.getNormalizedSourcePath();
96
-
97
- if (!fs.existsSync(genesisSourcePath)) {
98
- console.error(`Genesis source file not found at ${genesisSourcePath}`);
99
- process.exit(1);
100
- }
101
-
102
- const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
103
- const genesis = JSON.parse(raw);
104
-
105
- // Validate structure
106
- if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
107
- console.error('Genesis.json must have nucleusSchema.$defs');
108
- process.exit(1);
109
- }
110
-
111
- // Rewrite anchors in the nucleusSchema (pure function call)
112
- genesis.nucleusSchema = normalizeAnchorsToPointersToPointers(genesis.nucleusSchema);
113
-
114
- // Write normalized version
115
- fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
116
- fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
117
- console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
118
- }
119
-
120
- main().catch((e) => {
121
- console.error(e);
122
- process.exit(1);
123
- });
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { getConfig } from './_lib/config.js';
4
+
5
+ /*
6
+ * Rewrite anchor-style references to JSON Pointer references in Genesis.json.
7
+ * We also strip all $anchor fields from the output since they are no longer needed after rewriting refs.
8
+ */
9
+
10
+ // PURE: Remove all `$anchor` keys from a schema tree without rewriting refs.
11
+ export function stripAnchors<T>(schema: T): T {
12
+ const seen = new WeakMap<object, unknown>();
13
+
14
+ function walk(node: unknown): unknown {
15
+ if (!node || typeof node !== 'object') return node;
16
+
17
+ const existing = seen.get(node as object);
18
+ if (existing) return existing;
19
+
20
+ if (Array.isArray(node)) {
21
+ const out: unknown[] = [];
22
+ seen.set(node, out);
23
+ for (const item of node) out.push(walk(item));
24
+ return out;
25
+ }
26
+
27
+ const out: Record<string, unknown> = {};
28
+ seen.set(node as object, out);
29
+
30
+ for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
31
+ if (key === '$anchor') continue;
32
+ out[key] = walk(value);
33
+ }
34
+
35
+ return out;
36
+ }
37
+
38
+ return walk(schema) as T;
39
+ }
40
+
41
+ // PURE: Rewrite anchor-style `$ref` strings (`#Anchor`) into JSON Pointer refs (`#/$defs/DefName`).
42
+ function normalizeAnchorsToPointers(input: any): any {
43
+ if (!input || typeof input !== "object") return input;
44
+
45
+ // Deep clone the input to ensure the function is pure (no side effects on input)
46
+ const root = JSON.parse(JSON.stringify(input));
47
+
48
+ // Build a map of anchors to their definition names
49
+ const defs: Record<string, any> = root.$defs && typeof root.$defs === "object" ? root.$defs : {};
50
+ const anchorToDef: Record<string, string> = {};
51
+
52
+ // For Genesis structure: each def is a Type envelope with nucleusSchema.$anchor
53
+ for (const [defName, defValue] of Object.entries(defs)) {
54
+ if (!defValue || typeof defValue !== "object") continue;
55
+
56
+ // Check if this is a Type envelope (has nucleusSchema property)
57
+ const nucleusSchema = (defValue as any).nucleusSchema;
58
+ if (nucleusSchema && typeof nucleusSchema === "object") {
59
+ // Look for $anchor inside the nucleusSchema
60
+ const anchor = nucleusSchema.$anchor;
61
+ if (typeof anchor === "string" && !anchorToDef[anchor]) {
62
+ anchorToDef[anchor] = defName;
63
+ }
64
+ } else {
65
+ // Fallback: check for $anchor at the def level (non-envelope case)
66
+ const anchor = (defValue as any).$anchor;
67
+ if (typeof anchor === "string" && !anchorToDef[anchor]) {
68
+ anchorToDef[anchor] = defName;
69
+ }
70
+ }
71
+ }
72
+
73
+ // Walk the entire tree and rewrite anchor refs to pointer refs
74
+ function walk(node: any): void {
75
+ if (Array.isArray(node)) {
76
+ for (const item of node) walk(item);
77
+ return;
78
+ }
79
+ if (!node || typeof node !== "object") return;
80
+
81
+ // Rewrite $ref if it's an anchor-style reference
82
+ if (typeof node.$ref === "string") {
83
+ const ref: string = node.$ref;
84
+ // Match anchor refs: starts with # but not #/ (JSON Pointer syntax)
85
+ if (ref.startsWith("#") && !ref.startsWith("#/")) {
86
+ const anchor = ref.slice(1);
87
+ const defName = anchorToDef[anchor];
88
+ if (defName) {
89
+ node.$ref = `#/$defs/${defName}`;
90
+ }
91
+ }
92
+ }
93
+
94
+ // Recursively walk all properties
95
+ for (const val of Object.values(node)) {
96
+ walk(val);
97
+ }
98
+ }
99
+
100
+ walk(root);
101
+ return root;
102
+ }
103
+
104
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
105
+ function main() {
106
+ try {
107
+ const config = getConfig();
108
+ const genesisSourcePath = config.getSourcePath();
109
+
110
+ // Create a generated/normalized version (anchor refs rewritten to pointers)
111
+ const normalizedPath = config.getNormalizedSourcePath();
112
+
113
+ if (!fs.existsSync(genesisSourcePath)) {
114
+ throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
115
+ }
116
+
117
+ const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
118
+ const genesis = JSON.parse(raw);
119
+
120
+ // Validate structure
121
+ if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
122
+ throw new Error('Genesis.json must have nucleusSchema.$defs');
123
+ }
124
+
125
+ // Rewrite anchors in the nucleusSchema (pure function call)
126
+ genesis.nucleusSchema = normalizeAnchorsToPointers(genesis.nucleusSchema);
127
+
128
+ // Strip $anchor fields from the schemas (pure function call)
129
+ genesis.nucleusSchema = stripAnchors(genesis.nucleusSchema);
130
+
131
+ // Write normalized version
132
+ fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
133
+ fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
134
+ console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
135
+ } catch (e) {
136
+ console.error(e);
137
+ process.exitCode = 1;
138
+ }
139
+ }
140
+
141
+ main();
@@ -1,84 +1,82 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getConfig } from './_lib/config.js';
4
-
5
- /**
6
- * Wrap each ResourceType definition (from Genesis.nucleusSchema.$defs) with a Resource shell
7
- * that conforms to the Resource.nucleusSchema pattern defined in Genesis.json.
8
- */
9
-
10
- function generateResourceShellLogic(genesis: any): Record<string, any> {
11
- if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
12
- throw new Error('Genesis.json must have nucleusSchema.$defs');
13
- }
14
-
15
- const defs = genesis.nucleusSchema.$defs;
16
- const defKeys = Object.keys(defs);
17
-
18
- const resources: Record<string, any> = {};
19
-
20
- // Genesis timestamp: 2025-11-30T00:00:00.000Z marks the genesis of ToolProof
21
- const genesisTimestamp = '2025-11-30T00:00:00.000Z';
22
-
23
- resources['Genesis'] = {
24
- identity: 'RESOURCE-Genesis',
25
- resourceTypeHandle: 'TYPE-ResourceType',
26
- creationContext: {
27
- resourceRoleHandle: 'ROLE-Genesis',
28
- jobStepHandle: 'JOB_STEP-Genesis'
29
- },
30
- kind: 'materialized',
31
- timestamp: genesisTimestamp,
32
- nucleus: {}
33
- };
34
-
35
- defKeys.forEach((defName) => {
36
- const defValue = defs[defName];
37
-
38
- resources[defName] = {
39
- identity: `RESOURCE-${defName}`,
40
- resourceTypeHandle: 'TYPE-ResourceType',
41
- creationContext: {
42
- resourceRoleHandle: 'ROLE-Genesis',
43
- jobStepHandle: `JOB_STEP-${defName}`
44
- },
45
- kind: 'materialized',
46
- timestamp: genesisTimestamp,
47
- nucleus: defValue
48
- };
49
- });
50
-
51
- return resources;
52
- }
53
-
54
- async function main() {
55
- const config = getConfig();
56
- const genesisSourcePath = config.getNormalizedSourcePath();
57
- const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
58
-
59
- if (!fs.existsSync(genesisSourcePath)) {
60
- console.error(`Genesis source file not found at ${genesisSourcePath}`);
61
- process.exit(1);
62
- }
63
-
64
- const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
65
- const genesis = JSON.parse(raw);
66
-
67
- try {
68
- const resources = generateResourceShellLogic(genesis);
69
-
70
- const outputDir = path.dirname(outputPath);
71
- fs.mkdirSync(outputDir, { recursive: true });
72
-
73
- fs.writeFileSync(outputPath, JSON.stringify(resources, null, 4) + '\n', 'utf-8');
74
- console.log(`Generated ${Object.keys(resources).length} Resource envelopes -> ${outputPath}`);
75
- } catch (error: any) {
76
- console.error(error.message);
77
- process.exit(1);
78
- }
79
- }
80
-
81
- main().catch((e) => {
82
- console.error(e);
83
- process.exit(1);
84
- });
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { getConfig } from './_lib/config.js';
4
+
5
+ /**
6
+ * Wrap each ResourceType definition (from Genesis.nucleusSchema.$defs) with a Resource shell
7
+ * that conforms to the Resource.nucleusSchema pattern defined in Genesis.json.
8
+ */
9
+
10
+ // PURE: Build Resource shell envelopes for each $defs entry (no I/O, no mutation of inputs).
11
+ function generateResourceShellLogic(genesis: any): Record<string, any> {
12
+ if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
13
+ throw new Error('Genesis.json must have nucleusSchema.$defs');
14
+ }
15
+
16
+ const defs = genesis.nucleusSchema.$defs;
17
+ const defKeys = Object.keys(defs);
18
+
19
+ const resources: Record<string, any> = {};
20
+
21
+ // Genesis timestamp: 2025-11-30T00:00:00.000Z marks the genesis of ToolProof
22
+ const genesisTimestamp = '2025-11-30T00:00:00.000Z';
23
+
24
+ resources['Genesis'] = {
25
+ identity: 'RESOURCE-Genesis',
26
+ resourceTypeHandle: 'TYPE-ResourceType',
27
+ creationContext: {
28
+ resourceRoleHandle: 'ROLE-Genesis',
29
+ jobStepHandle: 'JOB_STEP-Genesis'
30
+ },
31
+ kind: 'materialized',
32
+ timestamp: genesisTimestamp,
33
+ nucleus: {}
34
+ };
35
+
36
+ defKeys.forEach((defName) => {
37
+ const defValue = defs[defName];
38
+
39
+ resources[defName] = {
40
+ identity: `RESOURCE-${defName}`,
41
+ resourceTypeHandle: 'TYPE-ResourceType',
42
+ creationContext: {
43
+ resourceRoleHandle: 'ROLE-Genesis',
44
+ jobStepHandle: `JOB_STEP-${defName}`
45
+ },
46
+ kind: 'materialized',
47
+ timestamp: genesisTimestamp,
48
+ nucleus: defValue
49
+ };
50
+ });
51
+
52
+ return resources;
53
+ }
54
+
55
+ // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
56
+ function main() {
57
+ try {
58
+ const config = getConfig();
59
+ const genesisSourcePath = config.getNormalizedSourcePath();
60
+ const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
61
+
62
+ if (!fs.existsSync(genesisSourcePath)) {
63
+ throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
64
+ }
65
+
66
+ const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
67
+ const genesis = JSON.parse(raw);
68
+
69
+ const resources = generateResourceShellLogic(genesis);
70
+
71
+ const outputDir = path.dirname(outputPath);
72
+ fs.mkdirSync(outputDir, { recursive: true });
73
+
74
+ fs.writeFileSync(outputPath, JSON.stringify(resources, null, 4) + '\n', 'utf-8');
75
+ console.log(`Generated ${Object.keys(resources).length} Resource envelopes -> ${outputPath}`);
76
+ } catch (error: any) {
77
+ console.error(error?.message ?? error);
78
+ process.exitCode = 1;
79
+ }
80
+ }
81
+
82
+ main();