@spellkave/tool-contracts 0.0.0-bootstrap

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 (121) hide show
  1. package/LICENSE +89 -0
  2. package/package.json +50 -0
  3. package/src/admission.ts +62 -0
  4. package/src/authoring-schemas.ts +3491 -0
  5. package/src/authoring-tool-names.ts +46 -0
  6. package/src/contract-data.ts +37 -0
  7. package/src/contract-guard.ts +377 -0
  8. package/src/contracts-metadata.json +6940 -0
  9. package/src/docs-metadata.ts +42 -0
  10. package/src/exploration.ts +248 -0
  11. package/src/git-batch.ts +36 -0
  12. package/src/grant-schemas.ts +38 -0
  13. package/src/index.ts +10 -0
  14. package/src/metadata.ts +48 -0
  15. package/src/owner-instance-read.ts +123 -0
  16. package/src/personas.generated.json +47 -0
  17. package/src/personas.ts +19 -0
  18. package/src/roster.ts +13 -0
  19. package/src/scene-schemas.ts +29 -0
  20. package/src/schema-registry.ts +197 -0
  21. package/src/schemas.ts +786 -0
  22. package/src/snapshot-storage.ts +133 -0
  23. package/src/tool-contracts.breaking-acknowledged.json +392 -0
  24. package/src/tool-contracts.snapshot/index.json +104 -0
  25. package/src/tool-contracts.snapshot/rosters/AUTHOR.json +54 -0
  26. package/src/tool-contracts.snapshot/rosters/DM.json +19 -0
  27. package/src/tool-contracts.snapshot/rosters/PLAYER.json +25 -0
  28. package/src/tool-contracts.snapshot/tools/spellkave_acting_context.json +35 -0
  29. package/src/tool-contracts.snapshot/tools/spellkave_actor_principals.json +23 -0
  30. package/src/tool-contracts.snapshot/tools/spellkave_annotate_place.json +82 -0
  31. package/src/tool-contracts.snapshot/tools/spellkave_apply_manifest_delta.json +66 -0
  32. package/src/tool-contracts.snapshot/tools/spellkave_applyset_apply.json +131 -0
  33. package/src/tool-contracts.snapshot/tools/spellkave_applyset_diff.json +122 -0
  34. package/src/tool-contracts.snapshot/tools/spellkave_attach_map_layer.json +114 -0
  35. package/src/tool-contracts.snapshot/tools/spellkave_author_place.json +132 -0
  36. package/src/tool-contracts.snapshot/tools/spellkave_bind_actor.json +79 -0
  37. package/src/tool-contracts.snapshot/tools/spellkave_bind_edge_affordance.json +69 -0
  38. package/src/tool-contracts.snapshot/tools/spellkave_can_i.json +123 -0
  39. package/src/tool-contracts.snapshot/tools/spellkave_communicate.json +44 -0
  40. package/src/tool-contracts.snapshot/tools/spellkave_declare_inexpressible.json +33 -0
  41. package/src/tool-contracts.snapshot/tools/spellkave_define_action.json +133 -0
  42. package/src/tool-contracts.snapshot/tools/spellkave_define_action_verb.json +215 -0
  43. package/src/tool-contracts.snapshot/tools/spellkave_define_affordance.json +69 -0
  44. package/src/tool-contracts.snapshot/tools/spellkave_define_behavior.json +505 -0
  45. package/src/tool-contracts.snapshot/tools/spellkave_define_bundle.json +67 -0
  46. package/src/tool-contracts.snapshot/tools/spellkave_define_capability.json +64 -0
  47. package/src/tool-contracts.snapshot/tools/spellkave_define_condition.json +244 -0
  48. package/src/tool-contracts.snapshot/tools/spellkave_define_consequence.json +65 -0
  49. package/src/tool-contracts.snapshot/tools/spellkave_define_entity_type.json +199 -0
  50. package/src/tool-contracts.snapshot/tools/spellkave_define_niche.json +88 -0
  51. package/src/tool-contracts.snapshot/tools/spellkave_define_resource.json +93 -0
  52. package/src/tool-contracts.snapshot/tools/spellkave_define_roll_table.json +87 -0
  53. package/src/tool-contracts.snapshot/tools/spellkave_define_session.json +115 -0
  54. package/src/tool-contracts.snapshot/tools/spellkave_define_trace_kind.json +71 -0
  55. package/src/tool-contracts.snapshot/tools/spellkave_describe.json +73 -0
  56. package/src/tool-contracts.snapshot/tools/spellkave_diff.json +90 -0
  57. package/src/tool-contracts.snapshot/tools/spellkave_docs.json +104 -0
  58. package/src/tool-contracts.snapshot/tools/spellkave_end_turn.json +21 -0
  59. package/src/tool-contracts.snapshot/tools/spellkave_entity.json +32 -0
  60. package/src/tool-contracts.snapshot/tools/spellkave_entity_body.json +32 -0
  61. package/src/tool-contracts.snapshot/tools/spellkave_entity_container.json +32 -0
  62. package/src/tool-contracts.snapshot/tools/spellkave_equip_item.json +49 -0
  63. package/src/tool-contracts.snapshot/tools/spellkave_eval.json +87 -0
  64. package/src/tool-contracts.snapshot/tools/spellkave_events.json +30 -0
  65. package/src/tool-contracts.snapshot/tools/spellkave_explain.json +83 -0
  66. package/src/tool-contracts.snapshot/tools/spellkave_export.json +66 -0
  67. package/src/tool-contracts.snapshot/tools/spellkave_export_grants.json +50 -0
  68. package/src/tool-contracts.snapshot/tools/spellkave_get.json +87 -0
  69. package/src/tool-contracts.snapshot/tools/spellkave_grant_role.json +80 -0
  70. package/src/tool-contracts.snapshot/tools/spellkave_hand_over_role.json +89 -0
  71. package/src/tool-contracts.snapshot/tools/spellkave_intervention_windows.json +32 -0
  72. package/src/tool-contracts.snapshot/tools/spellkave_inventory.json +40 -0
  73. package/src/tool-contracts.snapshot/tools/spellkave_item_detail.json +37 -0
  74. package/src/tool-contracts.snapshot/tools/spellkave_link_places.json +84 -0
  75. package/src/tool-contracts.snapshot/tools/spellkave_list_grants.json +56 -0
  76. package/src/tool-contracts.snapshot/tools/spellkave_manipulate.json +84 -0
  77. package/src/tool-contracts.snapshot/tools/spellkave_manipulation_context.json +62 -0
  78. package/src/tool-contracts.snapshot/tools/spellkave_map.json +109 -0
  79. package/src/tool-contracts.snapshot/tools/spellkave_map_graph.json +143 -0
  80. package/src/tool-contracts.snapshot/tools/spellkave_move.json +75 -0
  81. package/src/tool-contracts.snapshot/tools/spellkave_note_doc_gap.json +43 -0
  82. package/src/tool-contracts.snapshot/tools/spellkave_observer_knowledge.json +32 -0
  83. package/src/tool-contracts.snapshot/tools/spellkave_observer_place_knowledge.json +32 -0
  84. package/src/tool-contracts.snapshot/tools/spellkave_observer_trace_knowledge.json +32 -0
  85. package/src/tool-contracts.snapshot/tools/spellkave_offer_control.json +30 -0
  86. package/src/tool-contracts.snapshot/tools/spellkave_orient.json +39 -0
  87. package/src/tool-contracts.snapshot/tools/spellkave_pace_time.json +59 -0
  88. package/src/tool-contracts.snapshot/tools/spellkave_place_actor.json +190 -0
  89. package/src/tool-contracts.snapshot/tools/spellkave_place_entity.json +190 -0
  90. package/src/tool-contracts.snapshot/tools/spellkave_prepare_hand_over.json +57 -0
  91. package/src/tool-contracts.snapshot/tools/spellkave_query.json +290 -0
  92. package/src/tool-contracts.snapshot/tools/spellkave_react_option.json +47 -0
  93. package/src/tool-contracts.snapshot/tools/spellkave_reaction_options.json +32 -0
  94. package/src/tool-contracts.snapshot/tools/spellkave_release_claim.json +32 -0
  95. package/src/tool-contracts.snapshot/tools/spellkave_remove_entity.json +39 -0
  96. package/src/tool-contracts.snapshot/tools/spellkave_render_scene.json +59 -0
  97. package/src/tool-contracts.snapshot/tools/spellkave_return_npc_control.json +59 -0
  98. package/src/tool-contracts.snapshot/tools/spellkave_revoke_role.json +55 -0
  99. package/src/tool-contracts.snapshot/tools/spellkave_scene.json +74 -0
  100. package/src/tool-contracts.snapshot/tools/spellkave_scene_detail.json +37 -0
  101. package/src/tool-contracts.snapshot/tools/spellkave_self_states.json +77 -0
  102. package/src/tool-contracts.snapshot/tools/spellkave_self_summary.json +21 -0
  103. package/src/tool-contracts.snapshot/tools/spellkave_sense.json +68 -0
  104. package/src/tool-contracts.snapshot/tools/spellkave_sense_context.json +28 -0
  105. package/src/tool-contracts.snapshot/tools/spellkave_session_close.json +71 -0
  106. package/src/tool-contracts.snapshot/tools/spellkave_session_move.json +38 -0
  107. package/src/tool-contracts.snapshot/tools/spellkave_session_open.json +36 -0
  108. package/src/tool-contracts.snapshot/tools/spellkave_session_status.json +41 -0
  109. package/src/tool-contracts.snapshot/tools/spellkave_set_metadata.json +205 -0
  110. package/src/tool-contracts.snapshot/tools/spellkave_set_movement_default.json +58 -0
  111. package/src/tool-contracts.snapshot/tools/spellkave_stage_scene.json +55 -0
  112. package/src/tool-contracts.snapshot/tools/spellkave_status.json +23 -0
  113. package/src/tool-contracts.snapshot/tools/spellkave_stow_item.json +55 -0
  114. package/src/tool-contracts.snapshot/tools/spellkave_suggest_next_action.json +32 -0
  115. package/src/tool-contracts.snapshot/tools/spellkave_tag_entity.json +61 -0
  116. package/src/tool-contracts.snapshot/tools/spellkave_take_npc_control.json +64 -0
  117. package/src/tool-contracts.snapshot/tools/spellkave_trace_detail.json +36 -0
  118. package/src/tool-contracts.snapshot/tools/spellkave_traces.json +55 -0
  119. package/src/tool-contracts.snapshot/tools/spellkave_wake_up.json +23 -0
  120. package/src/tool-contracts.snapshot/tools/spellkave_withdraw_control.json +30 -0
  121. package/src/tool-contracts.snapshot/tools/spellkave_write_rows.json +62 -0
@@ -0,0 +1,46 @@
1
+ // Canonical AUTHOR tool names; execution stays in companion-agent during the additive cut.
2
+
3
+ export const DECLARE_INEXPRESSIBLE_TOOL = "spellkave_declare_inexpressible";
4
+ export const NOTE_DOC_GAP_TOOL = "spellkave_note_doc_gap";
5
+ export const DOCS_TOOL = "spellkave_docs";
6
+ export const APPLY_MANIFEST_DELTA_TOOL = "spellkave_apply_manifest_delta";
7
+ export const EXPORT_MANIFEST_TOOL = "spellkave_export";
8
+ export const DIFF_MANIFEST_TOOL = "spellkave_diff";
9
+ export const APPLYSET_DIFF_TOOL = "spellkave_applyset_diff";
10
+ export const APPLYSET_APPLY_TOOL = "spellkave_applyset_apply";
11
+ export const CAN_I_TOOL = "spellkave_can_i";
12
+ export const EXPLAIN_TOOL = "spellkave_explain";
13
+ export const GET_TOOL = "spellkave_get";
14
+ export const DESCRIBE_TOOL = "spellkave_describe";
15
+ export const QUERY_TOOL = "spellkave_query";
16
+ export const EVAL_TOOL = "spellkave_eval";
17
+ export const AUTHOR_PLACE_TOOL = "spellkave_author_place";
18
+ export const PLACE_ENTITY_TOOL = "spellkave_place_entity";
19
+ export const REMOVE_ENTITY_TOOL = "spellkave_remove_entity";
20
+ export const PLACE_ACTOR_TOOL = "spellkave_place_actor";
21
+ export const DEFINE_RESOURCE_TOOL = "spellkave_define_resource";
22
+ export const DEFINE_BEHAVIOR_TOOL = "spellkave_define_behavior";
23
+ export const DEFINE_ENTITY_TYPE_TOOL = "spellkave_define_entity_type";
24
+ export const DEFINE_ROLL_TABLE_TOOL = "spellkave_define_roll_table";
25
+ export const DEFINE_CONDITION_TOOL = "spellkave_define_condition";
26
+ export const DEFINE_NICHE_TOOL = "spellkave_define_niche";
27
+ export const DEFINE_AFFORDANCE_TOOL = "spellkave_define_affordance";
28
+ export const DEFINE_CAPABILITY_TOOL = "spellkave_define_capability";
29
+ export const DEFINE_CONSEQUENCE_TOOL = "spellkave_define_consequence";
30
+ export const DEFINE_ACTION_TOOL = "spellkave_define_action";
31
+ export const DEFINE_SESSION_TOOL = "spellkave_define_session";
32
+ export const DEFINE_ACTION_VERB_TOOL = "spellkave_define_action_verb";
33
+ export const WRITE_ROWS_TOOL = "spellkave_write_rows";
34
+ export const SET_METADATA_TOOL = "spellkave_set_metadata";
35
+ export const DEFINE_BUNDLE_TOOL = "spellkave_define_bundle";
36
+ export const BIND_ACTOR_TOOL = "spellkave_bind_actor";
37
+ export const TAG_ENTITY_TOOL = "spellkave_tag_entity";
38
+ export const EQUIP_ITEM_TOOL = "spellkave_equip_item";
39
+ export const STOW_ITEM_TOOL = "spellkave_stow_item";
40
+ export const DEFINE_TRACE_KIND_TOOL = "spellkave_define_trace_kind";
41
+ export const MAP_GRAPH_TOOL = "spellkave_map_graph";
42
+ export const LINK_PLACES_TOOL = "spellkave_link_places";
43
+ export const BIND_EDGE_AFFORDANCE_TOOL = "spellkave_bind_edge_affordance";
44
+ export const ATTACH_MAP_LAYER_TOOL = "spellkave_attach_map_layer";
45
+ export const ANNOTATE_PLACE_TOOL = "spellkave_annotate_place";
46
+ export const SET_MOVEMENT_DEFAULT_TOOL = "spellkave_set_movement_default";
@@ -0,0 +1,37 @@
1
+ import contractDataJson from "./contracts-metadata.json";
2
+
3
+ export const TOOL_ROLES = ["PLAYER", "DM", "AUTHOR"] as const;
4
+ export type ToolRole = (typeof TOOL_ROLES)[number];
5
+
6
+ export const TOOL_EXECUTION_MODES = ["parallel", "sequential"] as const;
7
+ export type ToolExecutionMode = (typeof TOOL_EXECUTION_MODES)[number];
8
+
9
+ export interface ToolCliMetadata {
10
+ positionals?: readonly string[];
11
+ examples?: readonly { command: string; description: string }[];
12
+ }
13
+
14
+ export type SerializedToolSchema = Record<string, unknown>;
15
+
16
+ export interface ToolContractData {
17
+ name: string;
18
+ admission: import("./admission").ToolAdmission;
19
+ authority?: { kind: "role-binding"; readSubject: boolean };
20
+ label: string;
21
+ description: string;
22
+ parameters: SerializedToolSchema;
23
+ executionMode: ToolExecutionMode;
24
+ promptSnippet?: string;
25
+ promptGuidelines?: readonly string[];
26
+ cli?: ToolCliMetadata;
27
+ roles: readonly ToolRole[];
28
+ }
29
+
30
+ export interface ToolContractDataFile {
31
+ format: "spellkave-tool-contracts/v1";
32
+ tools: readonly ToolContractData[];
33
+ rosters: Readonly<Record<ToolRole, readonly string[]>>;
34
+ }
35
+
36
+ /** Production contract data, hand-maintained: names, labels, descriptions, roles, CLI/prompt metadata. */
37
+ export const RAW_TOOL_CONTRACT_DATA = contractDataJson as ToolContractDataFile;
@@ -0,0 +1,377 @@
1
+ import { TOOL_ROLES, type ToolRole } from "./contract-data";
2
+
3
+ /**
4
+ * Replaces the retired sk-jay0.5.1.21.2 pre-cut parity freeze (bead closed;
5
+ * migration done). That test pinned every contract byte against a one-time
6
+ * historical snapshot forever, so any intentional improvement failed CI.
7
+ *
8
+ * This module implements the two checks a live package needs instead:
9
+ *
10
+ * - Rolling VISIBLE-DRIFT snapshots (`tool-contracts.snapshot/`): every
11
+ * change to a contract — new tool, new optional parameter, description
12
+ * text — must show up as a diff against the corresponding tool file, forcing a deliberate
13
+ * `pnpm --filter @spellkave/tool-contracts run capture-contracts` re-run.
14
+ * - A HARD compatibility gate that walks the diff between the previously
15
+ * *committed* snapshot (read from git, not the working tree — see
16
+ * `readCommittedSnapshot` in the Git baseline reader) and
17
+ * the live contracts, and refuses anything that could break a shipped
18
+ * client unless a matching entry exists in the acknowledgement sidecar.
19
+ */
20
+
21
+ export const CONTRACT_SNAPSHOT_FORMAT = "spellkave-tool-contracts/contract-snapshot/v1";
22
+
23
+ /** Serialised parameter shape: a plain JSON-Schema object (TypeBox IS JSON Schema). */
24
+ export type SerialisedSchema = Record<string, unknown>;
25
+
26
+ export interface SerialisedContract {
27
+ admission?: object;
28
+ authority?: object;
29
+ name: string;
30
+ label: string;
31
+ description: string;
32
+ parameters: SerialisedSchema;
33
+ executionMode: string;
34
+ promptSnippet?: string;
35
+ promptGuidelines?: readonly string[];
36
+ cli?: Record<string, unknown>;
37
+ roles: readonly ToolRole[];
38
+ }
39
+
40
+ export interface ContractSnapshotFile {
41
+ format: typeof CONTRACT_SNAPSHOT_FORMAT;
42
+ tools: readonly SerialisedContract[];
43
+ rosters: Readonly<Record<ToolRole, readonly string[]>>;
44
+ }
45
+
46
+ /** Known top-level fields: anything else on a contract is untyped drift the JSON cast can't catch. */
47
+ const KNOWN_CONTRACT_KEYS = new Set([
48
+ "name",
49
+ "label",
50
+ "description",
51
+ "parameters",
52
+ "executionMode",
53
+ "promptSnippet",
54
+ "promptGuidelines",
55
+ "cli",
56
+ "roles",
57
+ "authority",
58
+ "admission",
59
+ ]);
60
+
61
+ export function unknownContractFields(contract: object): string[] {
62
+ return Object.keys(contract).filter((key) => !KNOWN_CONTRACT_KEYS.has(key));
63
+ }
64
+
65
+ /** Deterministic key order so the committed snapshot diffs cleanly, field by field. */
66
+ export function serialiseContract(contract: {
67
+ name: string;
68
+ label: string;
69
+ description: string;
70
+ parameters: object;
71
+ executionMode: string;
72
+ promptSnippet?: string;
73
+ promptGuidelines?: readonly string[];
74
+ cli?: object;
75
+ authority?: object;
76
+ admission?: object;
77
+ roles: readonly ToolRole[];
78
+ }): SerialisedContract {
79
+ return {
80
+ name: contract.name,
81
+ label: contract.label,
82
+ description: contract.description,
83
+ parameters: JSON.parse(JSON.stringify(contract.parameters)) as SerialisedSchema,
84
+ executionMode: contract.executionMode,
85
+ ...(contract.promptSnippet === undefined ? {} : { promptSnippet: contract.promptSnippet }),
86
+ ...(contract.promptGuidelines === undefined
87
+ ? {}
88
+ : { promptGuidelines: [...contract.promptGuidelines] }),
89
+ ...(contract.cli === undefined
90
+ ? {}
91
+ : { cli: JSON.parse(JSON.stringify(contract.cli)) as Record<string, unknown> }),
92
+ roles: [...contract.roles],
93
+ ...(contract.authority === undefined ? {} : { authority: contract.authority }),
94
+ ...(contract.admission === undefined ? {} : { admission: contract.admission }),
95
+ };
96
+ }
97
+
98
+ export function captureSnapshot(
99
+ contracts: readonly {
100
+ name: string;
101
+ label: string;
102
+ description: string;
103
+ parameters: object;
104
+ executionMode: string;
105
+ promptSnippet?: string;
106
+ promptGuidelines?: readonly string[];
107
+ cli?: object;
108
+ roles: readonly ToolRole[];
109
+ }[],
110
+ rosters: Readonly<Record<ToolRole, readonly string[]>>,
111
+ ): ContractSnapshotFile {
112
+ return {
113
+ format: CONTRACT_SNAPSHOT_FORMAT,
114
+ tools: contracts.map(serialiseContract),
115
+ rosters: {
116
+ PLAYER: [...rosters.PLAYER],
117
+ DM: [...rosters.DM],
118
+ AUTHOR: [...rosters.AUTHOR],
119
+ },
120
+ };
121
+ }
122
+
123
+ export interface BreakingChange {
124
+ tool: string;
125
+ field: string;
126
+ description: string;
127
+ from: unknown;
128
+ to: unknown;
129
+ }
130
+
131
+ const TIGHTENABLE_CONSTRAINT_KEYS = [
132
+ "pattern",
133
+ "format",
134
+ "minimum",
135
+ "maximum",
136
+ "exclusiveMinimum",
137
+ "exclusiveMaximum",
138
+ "minLength",
139
+ "maxLength",
140
+ "minItems",
141
+ "maxItems",
142
+ "multipleOf",
143
+ "uniqueItems",
144
+ "additionalProperties",
145
+ ] as const;
146
+
147
+ function primitiveEqual(a: unknown, b: unknown): boolean {
148
+ return JSON.stringify(a) === JSON.stringify(b);
149
+ }
150
+
151
+ /** Enum-like value set: a plain `enum`, or a root/`anyOf` union of simple `{type, const}` literals. */
152
+ function constValues(node: Record<string, unknown>): unknown[] | null {
153
+ if (Array.isArray(node.enum)) return node.enum;
154
+ const anyOf = node.anyOf;
155
+ if (
156
+ Array.isArray(anyOf) &&
157
+ anyOf.every(
158
+ (branch) =>
159
+ branch !== null &&
160
+ typeof branch === "object" &&
161
+ "const" in (branch as Record<string, unknown>) &&
162
+ Object.keys(branch as Record<string, unknown>).every(
163
+ (key) => key === "type" || key === "const",
164
+ ),
165
+ )
166
+ ) {
167
+ return anyOf.map((branch) => (branch as { const: unknown }).const);
168
+ }
169
+ return null;
170
+ }
171
+
172
+ function compareSchemaNode(
173
+ tool: string,
174
+ path: string,
175
+ previous: Record<string, unknown>,
176
+ current: Record<string, unknown>,
177
+ changes: BreakingChange[],
178
+ ): void {
179
+ if (previous.type !== current.type) {
180
+ changes.push({
181
+ tool,
182
+ field: `${path}.type`,
183
+ description: "parameter type changed",
184
+ from: previous.type,
185
+ to: current.type,
186
+ });
187
+ }
188
+
189
+ const previousConsts = constValues(previous);
190
+ const currentConsts = constValues(current);
191
+ if (previousConsts !== null) {
192
+ const currentSet = new Set(currentConsts ?? []);
193
+ for (const value of previousConsts) {
194
+ if (!currentSet.has(value)) {
195
+ changes.push({
196
+ tool,
197
+ field: `${path}.enum`,
198
+ description: "enum/union value removed",
199
+ from: value,
200
+ to: undefined,
201
+ });
202
+ }
203
+ }
204
+ } else if (
205
+ (previous.anyOf !== undefined || current.anyOf !== undefined) &&
206
+ !primitiveEqual(previous.anyOf, current.anyOf)
207
+ ) {
208
+ changes.push({
209
+ tool,
210
+ field: `${path}.anyOf`,
211
+ description: "union shape changed",
212
+ from: previous.anyOf,
213
+ to: current.anyOf,
214
+ });
215
+ }
216
+
217
+ for (const key of TIGHTENABLE_CONSTRAINT_KEYS) {
218
+ if (!primitiveEqual(previous[key], current[key])) {
219
+ changes.push({
220
+ tool,
221
+ field: `${path}.${key}`,
222
+ description: "constraint changed",
223
+ from: previous[key],
224
+ to: current[key],
225
+ });
226
+ }
227
+ }
228
+
229
+ if (previous.type === "object") {
230
+ const previousRequired = new Set((previous.required as string[] | undefined) ?? []);
231
+ const currentRequired = new Set((current.required as string[] | undefined) ?? []);
232
+ for (const key of currentRequired) {
233
+ if (!previousRequired.has(key)) {
234
+ changes.push({
235
+ tool,
236
+ field: `${path}.required.${key}`,
237
+ description: "parameter newly required",
238
+ from: false,
239
+ to: true,
240
+ });
241
+ }
242
+ }
243
+
244
+ const previousProps = (previous.properties as Record<string, unknown> | undefined) ?? {};
245
+ const currentProps = (current.properties as Record<string, unknown> | undefined) ?? {};
246
+ for (const key of Object.keys(previousProps)) {
247
+ const propPath = `${path}.properties.${key}`;
248
+ if (!(key in currentProps)) {
249
+ changes.push({
250
+ tool,
251
+ field: propPath,
252
+ description: "parameter removed",
253
+ from: previousProps[key],
254
+ to: undefined,
255
+ });
256
+ continue;
257
+ }
258
+ compareSchemaNode(
259
+ tool,
260
+ propPath,
261
+ previousProps[key] as Record<string, unknown>,
262
+ currentProps[key] as Record<string, unknown>,
263
+ changes,
264
+ );
265
+ }
266
+ }
267
+
268
+ if (previous.type === "array" && current.type === "array" && previous.items && current.items) {
269
+ compareSchemaNode(
270
+ tool,
271
+ `${path}.items`,
272
+ previous.items as Record<string, unknown>,
273
+ current.items as Record<string, unknown>,
274
+ changes,
275
+ );
276
+ }
277
+ }
278
+
279
+ /**
280
+ * `previous === null` means no committed baseline exists yet (first capture):
281
+ * nothing to break, so it always reports clean.
282
+ */
283
+ export function computeBreakingChanges(
284
+ previous: ContractSnapshotFile | null,
285
+ current: ContractSnapshotFile,
286
+ ): BreakingChange[] {
287
+ if (previous === null) return [];
288
+ const changes: BreakingChange[] = [];
289
+ const previousByName = new Map(previous.tools.map((tool) => [tool.name, tool]));
290
+ const currentByName = new Map(current.tools.map((tool) => [tool.name, tool]));
291
+
292
+ for (const [name, previousTool] of previousByName) {
293
+ const currentTool = currentByName.get(name);
294
+ if (currentTool === undefined) {
295
+ changes.push({
296
+ tool: name,
297
+ field: "<tool>",
298
+ description: "tool removed or renamed",
299
+ from: name,
300
+ to: undefined,
301
+ });
302
+ continue;
303
+ }
304
+ if (previousTool.executionMode !== currentTool.executionMode) {
305
+ changes.push({
306
+ tool: name,
307
+ field: "executionMode",
308
+ description: "executionMode changed",
309
+ from: previousTool.executionMode,
310
+ to: currentTool.executionMode,
311
+ });
312
+ }
313
+ compareSchemaNode(
314
+ name,
315
+ "parameters",
316
+ previousTool.parameters as Record<string, unknown>,
317
+ currentTool.parameters as Record<string, unknown>,
318
+ changes,
319
+ );
320
+ }
321
+
322
+ for (const role of TOOL_ROLES) {
323
+ const currentSet = new Set(current.rosters[role]);
324
+ for (const name of previous.rosters[role]) {
325
+ if (!currentSet.has(name)) {
326
+ changes.push({
327
+ tool: name,
328
+ field: `roles.${role}`,
329
+ description: `dropped from the ${role} roster`,
330
+ from: role,
331
+ to: undefined,
332
+ });
333
+ }
334
+ }
335
+ }
336
+
337
+ return changes;
338
+ }
339
+
340
+ export interface BreakingChangeAcknowledgement {
341
+ tool: string;
342
+ field: string;
343
+ from: unknown;
344
+ to: unknown;
345
+ reason: string;
346
+ acknowledgedAt: string;
347
+ }
348
+
349
+ export const ACKNOWLEDGEMENTS_FORMAT =
350
+ "spellkave-tool-contracts/breaking-change-acknowledgements/v1";
351
+
352
+ export interface AcknowledgementsFile {
353
+ format: typeof ACKNOWLEDGEMENTS_FORMAT;
354
+ entries: readonly BreakingChangeAcknowledgement[];
355
+ }
356
+
357
+ function acknowledgementKey(entry: {
358
+ tool: string;
359
+ field: string;
360
+ from: unknown;
361
+ to: unknown;
362
+ }): string {
363
+ return JSON.stringify([entry.tool, entry.field, entry.from, entry.to]);
364
+ }
365
+
366
+ /** Every breaking change without a matching (tool, field, from, to) acknowledgement entry. */
367
+ export function unacknowledgedBreakingChanges(
368
+ changes: readonly BreakingChange[],
369
+ acknowledgements: AcknowledgementsFile,
370
+ ): BreakingChange[] {
371
+ const acknowledged = new Set(acknowledgements.entries.map(acknowledgementKey));
372
+ return changes.filter((change) => !acknowledged.has(acknowledgementKey(change)));
373
+ }
374
+
375
+ export function formatBreakingChange(change: BreakingChange): string {
376
+ return `${change.tool}: ${change.field} — ${change.description} (was ${JSON.stringify(change.from)}, now ${JSON.stringify(change.to)})`;
377
+ }