@treeseed/sdk 0.13.0-rc.122 → 0.13.0-rc.124

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 (126) hide show
  1. package/dist/agent-capacity/contracts/capacity/assignments/agent-execution.d.ts +1392 -974
  2. package/dist/agent-capacity/contracts/capacity/assignments/agent-execution.js +72 -27
  3. package/dist/agent-capacity/contracts/capacity/assignments/assignment-context-pack.d.ts +34 -34
  4. package/dist/agent-capacity/contracts/capacity/assignments/assignment-path.d.ts +2 -0
  5. package/dist/agent-capacity/contracts/capacity/assignments/assignment-path.js +13 -0
  6. package/dist/agent-capacity/contracts/capacity/assignments/assignment-records.d.ts +1 -0
  7. package/dist/agent-capacity/contracts/capacity/providers/supply-policy.d.ts +126 -1
  8. package/dist/agent-capacity/contracts/capacity/providers/supply-policy.js +35 -1
  9. package/dist/agent-capacity/contracts/capacity/workdays/assignment-allocation.d.ts +1 -3
  10. package/dist/agent-capacity/contracts/capacity/workdays/assignment-allocation.js +21 -15
  11. package/dist/agent-capacity/contracts/capacity/workdays/capability-accounting.d.ts +3 -42
  12. package/dist/agent-capacity/contracts/capacity/workdays/capability-accounting.js +8 -8
  13. package/dist/agent-capacity/contracts/capacity/workdays/workday-allocation.d.ts +227 -66
  14. package/dist/agent-capacity/contracts/capacity/workdays/workday-allocation.js +54 -19
  15. package/dist/agent-capacity/contracts/capacity/workdays/workday-records.d.ts +214 -5
  16. package/dist/agent-capacity/contracts/capacity/workdays/workday-records.js +19 -0
  17. package/dist/agent-capacity/contracts/operations/agent-team-clone.d.ts +47 -47
  18. package/dist/agent-capacity/contracts/projects/agents/project-agent-class.d.ts +119 -0
  19. package/dist/agent-capacity/contracts/projects/agents/project-agent-class.js +16 -0
  20. package/dist/agent-capacity/contracts/support/execution-graph.d.ts +434 -230
  21. package/dist/agent-capacity/contracts/support/execution-graph.js +20 -18
  22. package/dist/agent-capacity/contracts/support/financial-records.d.ts +2 -0
  23. package/dist/agent-capacity/validation/agent-definition-schema.d.ts +286 -254
  24. package/dist/agent-capacity/validation/agent-definition-schema.js +22 -28
  25. package/dist/agent-capacity/validation/agent-lab-forensics-schema.d.ts +1 -1
  26. package/dist/agent-capacity/validation/assignment-records.js +45 -0
  27. package/dist/capacity/agents/agent-capacity.d.ts +1 -0
  28. package/dist/capacity/agents/agent-capacity.js +1 -0
  29. package/dist/capacity-provider/capability-ontology.d.ts +102 -102
  30. package/dist/capacity-provider/client.d.ts +14 -7
  31. package/dist/capacity-provider/client.js +1 -4
  32. package/dist/capacity-provider/contracts/capacity-facts.d.ts +0 -1
  33. package/dist/capacity-provider/contracts/environment-profiles.d.ts +40 -40
  34. package/dist/capacity-provider/contracts/governance.d.ts +2 -17
  35. package/dist/capacity-provider/contracts/index.d.ts +2 -0
  36. package/dist/capacity-provider/contracts/index.js +2 -0
  37. package/dist/capacity-provider/core-capability-catalog.d.ts +7 -7
  38. package/dist/capacity-provider/environment-catalog.d.ts +22 -22
  39. package/dist/capacity-provider/environment-catalog.js +1 -1
  40. package/dist/capacity-provider/install-configuration.d.ts +4 -4
  41. package/dist/capacity-provider/sandbox-contracts.d.ts +54 -54
  42. package/dist/capacity-provider/source-workspace.d.ts +76 -76
  43. package/dist/capacity-provider/validation.d.ts +10 -2
  44. package/dist/capacity-provider/validation.js +52 -22
  45. package/dist/content/validation/agent-operational-content-schemas.d.ts +120 -118
  46. package/dist/content/validation/agent-operational-content-schemas.js +2 -0
  47. package/dist/content/validation/auxiliary-content-schemas.d.ts +92 -92
  48. package/dist/content/validation/content-model-schemas.d.ts +3155 -2512
  49. package/dist/content/validation/content-model-schemas.js +97 -87
  50. package/dist/content/validation/portable-content-data.d.ts +173 -168
  51. package/dist/content/validation/schema-constraints.d.ts +78 -0
  52. package/dist/content/validation/schema-constraints.js +149 -0
  53. package/dist/deployment/ai/storage.d.ts +20 -20
  54. package/dist/deployment/ai-hosting.d.ts +12 -12
  55. package/dist/deployment/ai-instance.d.ts +12 -12
  56. package/dist/deployment/ai-mode.d.ts +34 -34
  57. package/dist/deployment/hosted-topology-template.d.ts +25 -25
  58. package/dist/deployment/hosted-topology.d.ts +146 -146
  59. package/dist/deployment/postgres/transfer.d.ts +2 -2
  60. package/dist/deployment/schemas.d.ts +504 -504
  61. package/dist/development/schemas.d.ts +325 -325
  62. package/dist/graph/context-query-contracts.js +1 -1
  63. package/dist/guarantees/index.d.ts +26 -2
  64. package/dist/identity/contracts.js +6 -1
  65. package/dist/operator-contracts/canonical-command-tree.js +22 -8
  66. package/dist/operator-contracts/catalog/agents/agent-team-clone-operations.d.ts +27 -27
  67. package/dist/operator-contracts/catalog/capability-ontology-operations.d.ts +25 -25
  68. package/dist/operator-contracts/catalog/commands/command-tree-builders.d.ts +11 -9
  69. package/dist/operator-contracts/catalog/communication-operations.d.ts +108 -90
  70. package/dist/operator-contracts/catalog/hosted-topology-operations.d.ts +33 -33
  71. package/dist/operator-contracts/catalog/inbox-operations.d.ts +27 -27
  72. package/dist/operator-contracts/catalog/infrastructure/ai-instance-operations.d.ts +4 -4
  73. package/dist/operator-contracts/catalog/infrastructure/ai-instance-operations.js +2 -1
  74. package/dist/operator-contracts/catalog/knowledge-share-operations.d.ts +5 -5
  75. package/dist/operator-contracts/catalog/provider-environment-operations.d.ts +3 -3
  76. package/dist/operator-contracts/catalog/services/secret-operations.d.ts +16 -8
  77. package/dist/operator-contracts/catalog/services/secret-operations.js +2 -1
  78. package/dist/operator-contracts/catalog/workdays/profile-operations.d.ts +11 -11
  79. package/dist/operator-contracts/catalog/workdays/selection-commands.js +7 -6
  80. package/dist/operator-contracts/communication/contracts.d.ts +340 -198
  81. package/dist/operator-contracts/communication/contracts.js +6 -1
  82. package/dist/operator-contracts/control-plane-operation.d.ts +7 -0
  83. package/dist/operator-contracts/control-plane-operation.js +6 -0
  84. package/dist/operator-contracts/control-plane-operations.d.ts +469 -442
  85. package/dist/operator-contracts/control-plane-operations.js +26 -10
  86. package/dist/operator-contracts/inbox/contracts.d.ts +100 -100
  87. package/dist/operator-contracts/knowledge/contracts.d.ts +6 -6
  88. package/dist/operator-contracts/mcp.js +4 -3
  89. package/dist/operator-contracts/workday-lifecycle.d.ts +192 -2
  90. package/dist/operator-contracts/workday-lifecycle.js +108 -45
  91. package/dist/platform/agent-schema-verification.js +316 -33
  92. package/dist/platform/contracts.d.ts +72 -72
  93. package/dist/platform/schemas.d.ts +144 -36
  94. package/dist/platform/schemas.js +26 -0
  95. package/dist/platform/verification.js +4 -0
  96. package/dist/sdk-types/support/sdk-search-request.d.ts +2 -2
  97. package/dist/secrets-capability/secret-contracts.d.ts +2 -2
  98. package/dist/secrets-capability/shared-access.d.ts +1 -1
  99. package/dist/secrets-capability/shared-resources.d.ts +30 -30
  100. package/dist/security/encrypted-envelope.d.ts +6 -6
  101. package/dist/treedx/client.d.ts +4 -4
  102. package/dist/treedx/index.d.ts +1 -1
  103. package/dist/treedx/index.js +1 -0
  104. package/dist/treedx/types.d.ts +286 -0
  105. package/dist/treedx/types.js +44 -0
  106. package/dist/types/agents/agent-activity-profile.d.ts +1 -0
  107. package/guarantees/agent/golden/component-boundaries.guarantee.yaml +12 -0
  108. package/guarantees/agent/golden/product-custody.guarantee.yaml +12 -0
  109. package/guarantees/agent/golden/product.guarantee.yaml +12 -0
  110. package/guarantees/agent/golden/scenes/component-boundaries.scene.yaml +837 -0
  111. package/guarantees/agent/golden/scenes/product-custody.scene.yaml +53 -0
  112. package/guarantees/agent/golden/scenes/product.scene.yaml +8 -0
  113. package/guarantees/verifiers/golden.verifiers.yaml +1429 -0
  114. package/package.json +10 -5
  115. package/tests/acceptance/golden-product.test.ts +205 -0
  116. package/tests/acceptance/golden-product.ts +404 -0
  117. package/tests/acceptance/product/base-red.ts +73 -0
  118. package/tests/acceptance/product/documentation-examples.ts +68 -0
  119. package/tests/acceptance/product/intent-runtime.ts +145 -0
  120. package/tests/acceptance/product/release-output.ts +160 -0
  121. package/tests/acceptance/product/research-artifact.ts +87 -0
  122. package/tests/acceptance/product/research-revision.ts +82 -0
  123. package/tests/acceptance/product/research-source.ts +91 -0
  124. package/tests/acceptance/product/test-chain.ts +192 -0
  125. package/treeseed.package.yaml +147 -0
  126. package/dist/.treeseed-build-complete.json +0 -1
@@ -1,90 +1,373 @@
1
1
  import { describeContentFrontmatterSchema } from "../content/validation/content-model-schemas.js";
2
2
  import { zodToJsonSchema } from "zod-to-json-schema";
3
+ import { z } from "zod";
4
+ import { exportSchemaConstraints } from "../content/validation/schema-constraints.js";
5
+ import {
6
+ assignmentAttemptSchema,
7
+ assignmentContextSchema,
8
+ assignmentResultSchema,
9
+ usageSettlementSchema,
10
+ leaseSchema,
11
+ reservationSchema,
12
+ exactEntityReferenceSchema,
13
+ exactGrantSchema,
14
+ assignmentWorkspaceSchema,
15
+ estimateSchema
16
+ } from "../agent-capacity/contracts/capacity/assignments/agent-execution.js";
17
+ import {
18
+ assignmentReferenceSchema,
19
+ effectiveActivityProfileSchema,
20
+ authorizedContextItemSchema,
21
+ verificationRecordSchema,
22
+ usageSchema,
23
+ diagnosticSchema,
24
+ assignmentTimingAwarenessReceiptSchema
25
+ } from "../agent-capacity/contracts/capacity/assignments/agent-execution.js";
26
+ import {
27
+ executionNodeSchema,
28
+ executionEdgeSchema,
29
+ graphRevisionSchema,
30
+ graphChangeSetSchema,
31
+ conditionDefinitionSchema
32
+ } from "../agent-capacity/validation/execution/execution-graph.js";
33
+ import { appliedWorkdaySchema, workdayPolicySchema, workdayProfileSchema, weightMapSchema, projectWeightSchema, agentClassWeightSchema } from "../agent-capacity/contracts/capacity/workdays/workday-allocation.js";
34
+ import { activityProfileSchema, activityProfilesSchema } from "../agent-capacity/validation/agent-definition-schema.js";
35
+ import { providerOfferSchema, providerStateSchema, availabilityWindowSchema, nativeLimitSchema } from "../agent-capacity/contracts/capacity/providers/supply-policy.js";
36
+ import { treeDxWorkspaceSchema, treeDxWorkspaceReviewSchema, treeDxPublicationReceiptSchema } from "../treedx/types.js";
37
+ import { teamRecordSchema, projectRecordSchema, repositoryBindingSchema, treeDxBindingSchema } from "./schemas.js";
38
+ import { agentRegistrationSchema } from "../agent-capacity/contracts/projects/agents/project-agent-class.js";
39
+ import { workdayIntentSchema } from "../operator-contracts/workday-lifecycle.js";
40
+ import { workdayScheduleSchema } from "../agent-capacity/contracts/capacity/workdays/workday-records.js";
3
41
  const models = {
4
42
  Book: "book",
5
43
  Knowledge: "knowledge",
6
44
  Objective: "objective",
7
45
  Discussion: "discussion",
8
- DiscussionMessage: "discussion_message"
46
+ DiscussionMessage: "discussion_message",
47
+ AgentProfile: "agent",
48
+ Proposal: "proposal",
49
+ Question: "question",
50
+ Note: "note",
51
+ Decision: "decision"
9
52
  };
53
+ const runtimeSchemas = {
54
+ WeightMap: weightMapSchema,
55
+ ProjectWeight: projectWeightSchema,
56
+ AgentClassWeight: agentClassWeightSchema,
57
+ WorkdayIntent: workdayIntentSchema,
58
+ RepositoryBinding: repositoryBindingSchema,
59
+ TreeDxBinding: treeDxBindingSchema,
60
+ AvailabilityWindow: availabilityWindowSchema,
61
+ NativeLimit: nativeLimitSchema,
62
+ AssignmentContext: assignmentContextSchema,
63
+ ExactEntityReference: exactEntityReferenceSchema,
64
+ ExactGrant: exactGrantSchema,
65
+ AssignmentWorkspace: assignmentWorkspaceSchema,
66
+ Estimate: estimateSchema,
67
+ AssignmentReference: assignmentReferenceSchema,
68
+ GitReference: assignmentReferenceSchema.options[0],
69
+ TreeDxReference: assignmentReferenceSchema.options[1],
70
+ UrlReference: assignmentReferenceSchema.options[2],
71
+ ReadOnlyWorkspace: assignmentWorkspaceSchema.options[0],
72
+ TreeDxAssignmentWorkspace: assignmentWorkspaceSchema.options[1],
73
+ GitAssignmentWorkspace: assignmentWorkspaceSchema.options[2],
74
+ EffectiveActivityProfile: effectiveActivityProfileSchema,
75
+ AuthorizedContextItem: authorizedContextItemSchema,
76
+ VerificationRecord: verificationRecordSchema,
77
+ Usage: usageSchema,
78
+ Diagnostic: diagnosticSchema,
79
+ AssignmentTimingAwarenessReceipt: assignmentTimingAwarenessReceiptSchema,
80
+ GraphChangeSet: graphChangeSetSchema,
81
+ ConditionDefinition: conditionDefinitionSchema,
82
+ WorkdayPolicyFields: workdayPolicySchema,
83
+ ActivityProfile: activityProfileSchema,
84
+ ActivityProfiles: activityProfilesSchema,
85
+ PlanningRound: appliedWorkdaySchema.innerType().shape.planningRounds.element,
86
+ AssignmentLimits: assignmentAttemptSchema.innerType().shape.limits,
87
+ ProviderOfferSelection: assignmentAttemptSchema.innerType().shape.provider
88
+ };
89
+ const schemas = {
90
+ Team: teamRecordSchema,
91
+ Project: projectRecordSchema,
92
+ AgentRegistration: agentRegistrationSchema,
93
+ WorkdaySchedule: workdayScheduleSchema,
94
+ ...Object.fromEntries(Object.entries(models).map(([name, model]) => [name, describeContentFrontmatterSchema(model)])),
95
+ ProviderOffer: providerOfferSchema,
96
+ ProviderState: providerStateSchema,
97
+ TreeDxWorkspace: treeDxWorkspaceSchema,
98
+ TreeDxWorkspaceReview: treeDxWorkspaceReviewSchema,
99
+ TreeDxPublicationReceipt: treeDxPublicationReceiptSchema,
100
+ AssignmentAttempt: assignmentAttemptSchema,
101
+ AssignmentResult: assignmentResultSchema,
102
+ UsageSettlement: usageSettlementSchema,
103
+ Lease: leaseSchema,
104
+ Reservation: reservationSchema,
105
+ ExecutionNode: executionNodeSchema,
106
+ ExecutionEdge: executionEdgeSchema,
107
+ Workday: appliedWorkdaySchema,
108
+ GraphRevision: graphRevisionSchema,
109
+ WorkdayPolicy: workdayProfileSchema,
110
+ ...runtimeSchemas
111
+ };
112
+ const runtimeOnly = new Set(Object.keys(runtimeSchemas));
10
113
  function record(value) {
11
114
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
12
115
  }
13
- function dereference(schema, root) {
14
- const reference = typeof schema.$ref === "string" ? schema.$ref : "";
15
- if (!reference.startsWith("#/$defs/")) return schema;
16
- return {
17
- ...record(record(root.$defs)[reference.slice("#/$defs/".length)]),
18
- ...Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "$ref"))
19
- };
116
+ function dereference(schema, root, references) {
117
+ while (typeof schema.$ref === "string" && schema.$ref.startsWith("#/")) {
118
+ const reference = schema.$ref;
119
+ if (references.has(reference)) return schema;
120
+ references.add(reference);
121
+ const parts = reference.slice(2).split("/");
122
+ if (parts.some((part) => /~(?![01])/u.test(part))) return schema;
123
+ let selected = root;
124
+ for (const part of parts) {
125
+ const key = part.replace(/~1/gu, "/").replace(/~0/gu, "~");
126
+ if (!selected || typeof selected !== "object" || !Object.hasOwn(selected, key)) return schema;
127
+ selected = Object.getOwnPropertyDescriptor(selected, key)?.value;
128
+ }
129
+ if (selected === false) return false;
130
+ if (selected !== true && (!selected || typeof selected !== "object" || Array.isArray(selected))) return schema;
131
+ schema = { ...record(selected), ...Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "$ref")) };
132
+ }
133
+ return schema;
134
+ }
135
+ function disjointTaggedBranches(value) {
136
+ if (!Array.isArray(value) || !value.length) return false;
137
+ const branches = value.map(record), first = branches[0];
138
+ if (branches.some((branch) => branch.type !== "object" || !Array.isArray(branch.required))) return false;
139
+ return first.required.some((field) => {
140
+ if (typeof field !== "string") return false;
141
+ const tags = [];
142
+ for (const branch of branches) {
143
+ if (!branch.required.includes(field)) return false;
144
+ const tag = record(record(branch.properties)[field]);
145
+ if (!Object.hasOwn(tag, "const")) return false;
146
+ const literal = tag.const;
147
+ if (literal !== null && typeof literal !== "string" && typeof literal !== "boolean" && !(typeof literal === "number" && Number.isFinite(literal))) return false;
148
+ tags.push(JSON.stringify(literal));
149
+ }
150
+ return new Set(tags).size === branches.length;
151
+ });
152
+ }
153
+ function finiteValuesImplyType(schema) {
154
+ const values = Object.hasOwn(schema, "const") ? [schema.const] : Array.isArray(schema.enum) ? schema.enum : [];
155
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
156
+ return values.length > 0 && values.every((value) => types.some((type) => type === "null" ? value === null : type === "array" ? Array.isArray(value) : type === "object" ? value !== null && typeof value === "object" && !Array.isArray(value) : type === "integer" ? typeof value === "number" && Number.isInteger(value) : type === "number" ? typeof value === "number" && Number.isFinite(value) : typeof value === type));
20
157
  }
21
- function structuralSchema(value, root) {
22
- const schema = dereference(record(value), root);
158
+ function finiteValues(value) {
159
+ const schema = record(value), keys = Object.keys(schema);
160
+ if (keys.length !== 1) return void 0;
161
+ const values = keys[0] === "const" ? [schema.const] : keys[0] === "enum" && Array.isArray(schema.enum) ? schema.enum : schema.type === "null" ? [null] : void 0;
162
+ if (!values?.length || values.some((item) => item !== null && typeof item !== "string" && typeof item !== "boolean" && !(typeof item === "number" && Number.isFinite(item)))) return void 0;
163
+ return values;
164
+ }
165
+ function finiteSchema(values) {
166
+ const unique = [...new Map(values.map((value) => [JSON.stringify(value), value])).entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, value]) => value);
167
+ return unique.length === 1 ? { const: unique[0] } : { enum: unique };
168
+ }
169
+ function structuralSchema(value, root, ancestors = /* @__PURE__ */ new Set(), inheritedObject = false, cache = /* @__PURE__ */ new WeakMap()) {
170
+ if (!value || typeof value !== "object") return structuralSchemaValue(value, root, ancestors, inheritedObject, cache);
171
+ const key = JSON.stringify([[...ancestors].sort(), inheritedObject]), entries = cache.get(value) ?? /* @__PURE__ */ new Map();
172
+ if (entries.has(key)) return entries.get(key);
173
+ const result = structuralSchemaValue(value, root, ancestors, inheritedObject, cache);
174
+ entries.set(key, result);
175
+ cache.set(value, entries);
176
+ return result;
177
+ }
178
+ function structuralSchemaValue(value, root, ancestors, inheritedObject, cache) {
179
+ if (typeof value === "boolean") return value ? {} : false;
180
+ const references = new Set(ancestors), schema = dereference(record(value), root, references);
181
+ if (schema === false) return false;
23
182
  const normalized = {};
24
- for (const key of ["type", "const", "enum", "minLength", "maxLength", "pattern", "format", "minimum", "maximum", "minItems", "maxItems"]) {
183
+ for (const key of [
184
+ "$ref",
185
+ "type",
186
+ "const",
187
+ "enum",
188
+ "minLength",
189
+ "maxLength",
190
+ "pattern",
191
+ "format",
192
+ "minimum",
193
+ "maximum",
194
+ "exclusiveMinimum",
195
+ "exclusiveMaximum",
196
+ "multipleOf",
197
+ "minItems",
198
+ "maxItems",
199
+ "minProperties",
200
+ "maxProperties",
201
+ "uniqueItems",
202
+ "minContains",
203
+ "maxContains"
204
+ ]) {
25
205
  if (schema[key] !== void 0) normalized[key] = schema[key];
26
206
  }
27
- if (normalized.type === "integer" && schema.exclusiveMinimum === 0 && normalized.minimum === void 0) normalized.minimum = 1;
28
- if (normalized.const !== void 0 || normalized.enum !== void 0) delete normalized.type;
29
- if (schema.items !== void 0) normalized.items = structuralSchema(schema.items, root);
30
- if (schema.properties !== void 0) normalized.properties = Object.fromEntries(
31
- Object.entries(record(schema.properties)).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, structuralSchema(child, root)])
207
+ const objectAuthority = inheritedObject || schema.type === "object";
208
+ if (inheritedObject && normalized.type === "object") delete normalized.type;
209
+ if (normalized.type === "integer" && schema.exclusiveMinimum === 0 && normalized.minimum === void 0) {
210
+ normalized.minimum = 1;
211
+ delete normalized.exclusiveMinimum;
212
+ }
213
+ if (!Object.hasOwn(normalized, "const") && Array.isArray(normalized.enum) && normalized.enum.length === 1) {
214
+ normalized.const = normalized.enum[0];
215
+ delete normalized.enum;
216
+ }
217
+ if (finiteValuesImplyType(normalized)) delete normalized.type;
218
+ for (const key of ["items", "contains", "not", "if", "then", "else", "propertyNames", "unevaluatedItems", "unevaluatedProperties"]) {
219
+ if (schema[key] !== void 0) normalized[key] = structuralSchema(
220
+ schema[key],
221
+ root,
222
+ references,
223
+ objectAuthority && ["not", "if", "then", "else"].includes(key),
224
+ cache
225
+ );
226
+ }
227
+ for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
228
+ if (schema[key] !== void 0) normalized[key] = Array.isArray(schema[key]) ? schema[key].map((child) => structuralSchema(child, root, references, objectAuthority && key !== "prefixItems", cache)) : schema[key];
229
+ }
230
+ if (normalized.anyOf === void 0 && disjointTaggedBranches(normalized.oneOf)) {
231
+ normalized.anyOf = normalized.oneOf;
232
+ delete normalized.oneOf;
233
+ }
234
+ if (disjointTaggedBranches(normalized.anyOf)) normalized.anyOf = [...normalized.anyOf].sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
235
+ for (const key of ["properties", "patternProperties", "dependentSchemas"]) {
236
+ if (schema[key] !== void 0) normalized[key] = Object.fromEntries(
237
+ Object.entries(record(schema[key])).sort(([left], [right]) => left.localeCompare(right)).map(([name, child]) => [name, structuralSchema(child, root, references, false, cache)])
238
+ );
239
+ }
240
+ if (schema.dependentRequired !== void 0) normalized.dependentRequired = Object.fromEntries(
241
+ Object.entries(record(schema.dependentRequired)).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, Array.isArray(child) ? [...child].sort() : child])
32
242
  );
33
243
  if (Array.isArray(schema.required)) normalized.required = [...schema.required].sort();
34
244
  if (schema.additionalProperties === false) normalized.additionalProperties = false;
35
245
  else if (schema.additionalProperties && Object.keys(record(schema.additionalProperties)).length) {
36
- normalized.additionalProperties = structuralSchema(schema.additionalProperties, root);
246
+ normalized.additionalProperties = structuralSchema(schema.additionalProperties, root, references, false, cache);
247
+ }
248
+ const finite = finiteValues(normalized);
249
+ if (finite) return finiteSchema(finite);
250
+ if (Object.keys(normalized).length === 1) {
251
+ const key = normalized.anyOf !== void 0 ? "anyOf" : "oneOf", union = normalized[key];
252
+ if (Array.isArray(union) && union.length) {
253
+ const branches = union.map(finiteValues);
254
+ if (branches.every((branch) => branch !== void 0)) {
255
+ const values = branches.flat();
256
+ if (key === "anyOf" || new Set(values.map((value2) => JSON.stringify(value2))).size === values.length) {
257
+ return finiteSchema(values);
258
+ }
259
+ }
260
+ }
37
261
  }
38
262
  return normalized;
39
263
  }
40
264
  function structuralDifferences(expected, actual, path = "") {
41
265
  if (JSON.stringify(expected) === JSON.stringify(actual)) return [];
42
- if (!expected || !actual || typeof expected !== "object" || typeof actual !== "object" || Array.isArray(expected) || Array.isArray(actual)) return [path || "<root>"];
266
+ if (!expected || !actual || typeof expected !== "object" || typeof actual !== "object" || Array.isArray(expected) !== Array.isArray(actual)) return [
267
+ `${path || "<root>"}: declaration ${JSON.stringify(expected)}, executable ${JSON.stringify(actual)}`
268
+ ];
43
269
  const left = expected, right = actual;
44
270
  return [.../* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])].sort().flatMap((key) => structuralDifferences(left[key], right[key], path ? `${path}.${key}` : key));
45
271
  }
272
+ const executableStructures = new Map(Object.entries(schemas).map(([name, schema]) => {
273
+ const generated = record(zodToJsonSchema(schema, { name, $refStrategy: "none", postProcess: exportSchemaConstraints }));
274
+ let base = schema;
275
+ while (base instanceof z.ZodEffects) base = base.innerType();
276
+ const shape = base instanceof z.ZodObject ? base.shape : {};
277
+ const keys = Object.keys(shape).sort(), required = keys.filter((key) => !shape[key].isOptional());
278
+ return [name, {
279
+ object: base instanceof z.ZodObject,
280
+ shape,
281
+ keys,
282
+ required,
283
+ structure: JSON.stringify(structuralSchema(record(record(generated.definitions)[name]), generated))
284
+ }];
285
+ }));
46
286
  function verifyAgentContentSchema(document, path = "docs/agent.schema.yml") {
47
287
  const definitions = document?.$defs ?? {};
48
288
  const diagnostics = [];
49
- for (const [definition, model] of Object.entries(models)) {
289
+ const structures = /* @__PURE__ */ new WeakMap();
290
+ for (const [name, value] of Object.entries(definitions)) if (!Object.keys(record(value)).length)
291
+ diagnostics.push({ code: "agent_schema_missing", path, message: `${name} definition is missing or unconstrained.` });
292
+ const union = record(document).oneOf;
293
+ if (!Array.isArray(union) || !union.length) diagnostics.push({
294
+ code: "agent_schema_root_missing",
295
+ path,
296
+ message: "The stored-record root must declare a nonempty oneOf union; a content-model subset is not complete authority."
297
+ });
298
+ else {
299
+ const seen = /* @__PURE__ */ new Set();
300
+ for (const entry of union) {
301
+ const reference = record(entry).$ref;
302
+ const match = typeof reference === "string" ? /^#\/\$defs\/([^/]+)$/u.exec(reference) : null;
303
+ const name = match?.[1];
304
+ if (!name || Object.keys(record(entry)).length !== 1) diagnostics.push({
305
+ code: "agent_schema_root_invalid",
306
+ path,
307
+ message: `Stored-record root reference ${String(reference)} must identify one exact local definition.`
308
+ });
309
+ else {
310
+ if (seen.has(name)) diagnostics.push({ code: "agent_schema_root_duplicate", path, message: `Stored-record root repeats ${name}.` });
311
+ seen.add(name);
312
+ if (!Object.hasOwn(definitions, name) || !Object.keys(record(definitions[name])).length) diagnostics.push({
313
+ code: "agent_schema_missing",
314
+ path,
315
+ message: `${name} root authority is missing or unconstrained.`
316
+ });
317
+ else if (runtimeOnly.has(name)) diagnostics.push({
318
+ code: "agent_schema_root_invalid",
319
+ path,
320
+ message: `${name} is a runtime/shared contract, not a stored-record root member.`
321
+ });
322
+ else if (!Object.hasOwn(schemas, name)) diagnostics.push({
323
+ code: "agent_schema_unverified",
324
+ path,
325
+ message: `${name} stored-record authority has no executable schema equivalence implementation.`
326
+ });
327
+ }
328
+ }
329
+ for (const name of Object.keys(schemas)) if (!runtimeOnly.has(name) && !seen.has(name)) {
330
+ diagnostics.push({
331
+ code: "agent_schema_root_missing",
332
+ path,
333
+ message: `${name} executable stored-record authority is absent from the root union.`
334
+ });
335
+ }
336
+ }
337
+ for (const [definition, executable] of executableStructures) {
50
338
  const declared = definitions[definition];
51
- const schema = describeContentFrontmatterSchema(model);
52
- const shape = "shape" in schema ? schema.shape : {};
53
- if (!declared?.properties || !Array.isArray(declared.required)) {
339
+ const { shape, keys: actualKeys, required } = executable;
340
+ if (!declared || typeof declared !== "object" || executable.object && !declared.properties) {
54
341
  diagnostics.push({ code: "agent_schema_missing", path, message: `${definition} must declare properties and required fields.` });
55
342
  continue;
56
343
  }
57
- const declaredKeys = Object.keys(declared.properties).sort();
58
- const actualKeys = Object.keys(shape).sort();
344
+ const declaredKeys = Object.keys(declared.properties ?? {}).sort();
59
345
  const missing = actualKeys.filter((key) => !declaredKeys.includes(key));
60
346
  const extra = declaredKeys.filter((key) => !actualKeys.includes(key));
61
347
  if (missing.length || extra.length) diagnostics.push({
62
348
  code: "agent_schema_fields_mismatch",
63
349
  path,
64
- message: `${definition} differs from SDK ${model} fields; missing: ${missing.join(", ") || "none"}; extra: ${extra.join(", ") || "none"}.`
350
+ message: `${definition} differs from SDK executable fields; missing: ${missing.join(", ") || "none"}; extra: ${extra.join(", ") || "none"}.`
65
351
  });
66
- const required = actualKeys.filter((key) => !shape[key].isOptional()).sort();
67
- const declaredRequired = [...declared.required].sort();
352
+ const declaredRequired = [...declared.required ?? []].sort();
68
353
  if (JSON.stringify(required) !== JSON.stringify(declaredRequired)) diagnostics.push({
69
354
  code: "agent_schema_required_mismatch",
70
355
  path,
71
356
  message: `${definition} required fields differ; SDK: ${required.join(", ") || "none"}; declaration: ${declaredRequired.join(", ") || "none"}.`
72
357
  });
73
- for (const [field, specification] of Object.entries(declared.properties)) {
358
+ for (const [field, specification] of Object.entries(declared.properties ?? {})) {
74
359
  if (specification && Object.hasOwn(specification, "const") && shape[field] && !shape[field].safeParse(specification.const).success) diagnostics.push({
75
360
  code: "agent_schema_constant_mismatch",
76
361
  path,
77
362
  message: `${definition}.${field} constant is rejected by the SDK validator.`
78
363
  });
79
364
  }
80
- const generated = record(zodToJsonSchema(schema, { name: definition, $refStrategy: "none" }));
81
- const generatedDefinition = record(record(generated.definitions)[definition]);
82
- const expectedStructure = JSON.stringify(structuralSchema(declared, document));
83
- const actualStructure = JSON.stringify(structuralSchema(generatedDefinition, generated));
365
+ const expectedStructure = JSON.stringify(structuralSchema(declared, document, /* @__PURE__ */ new Set(), false, structures));
366
+ const actualStructure = executable.structure;
84
367
  if (expectedStructure !== actualStructure) diagnostics.push({
85
368
  code: "agent_schema_structure_mismatch",
86
369
  path,
87
- message: `${definition} nested declarative constraints differ from the SDK validator at ${structuralDifferences(JSON.parse(expectedStructure), JSON.parse(actualStructure)).slice(0, 8).join(", ")}.`
370
+ message: `${definition} nested declarative constraints differ from the SDK validator at ${structuralDifferences(JSON.parse(expectedStructure), JSON.parse(actualStructure)).join("; ")}.`
88
371
  });
89
372
  }
90
373
  return diagnostics;