@mfdaves/okf-mcp 0.9.1 → 0.13.0-rc.1

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 (115) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +452 -26
  3. package/bin/okf-mcp.js +6 -1
  4. package/okf/okf-mcp/distribution/reference-bundle.md +10 -3
  5. package/okf/okf-mcp/index.md +2 -1
  6. package/okf/okf-mcp/interfaces/http-authoring-api.md +11 -2
  7. package/okf/okf-mcp/interfaces/mcp-http.md +64 -0
  8. package/okf/okf-mcp/interfaces/mcp-tools.md +25 -6
  9. package/okf/okf-mcp/overview/okf-mcp.md +16 -6
  10. package/okf/okf-mcp/policies/authoring-safety.md +28 -5
  11. package/okf/okf-mcp/runtime/indexer.md +14 -1
  12. package/okf/okf-mcp/runtime/mcp-server.md +16 -8
  13. package/okf/okf-mcp/specs/producer-api.md +16 -2
  14. package/package.json +17 -5
  15. package/server.json +38 -2
  16. package/src/assets.js +165 -73
  17. package/src/authoring/candidates.js +434 -0
  18. package/src/authoring/git-preflight.js +225 -0
  19. package/src/authoring/git-publish.js +783 -0
  20. package/src/authoring/live.js +757 -0
  21. package/src/authoring/paths.js +112 -0
  22. package/src/authoring/policy-hook.js +221 -0
  23. package/src/authoring/proposal-policy.js +159 -0
  24. package/src/authoring/receipts.js +373 -0
  25. package/src/authoring/render.js +38 -0
  26. package/src/authoring/shared.js +75 -0
  27. package/src/authoring/staging.js +216 -0
  28. package/src/authoring.js +386 -287
  29. package/src/cache/files.js +147 -0
  30. package/src/cache/lock.js +201 -0
  31. package/src/cache/paths.js +197 -0
  32. package/src/cache/store.js +703 -0
  33. package/src/catalog-text.js +19 -0
  34. package/src/cli/commands.js +448 -0
  35. package/src/cli/http-options.js +193 -0
  36. package/src/cli/options.js +554 -0
  37. package/src/cli/usage.js +96 -0
  38. package/src/cli.js +18 -932
  39. package/src/computation.js +99 -61
  40. package/src/context/assemble.js +567 -0
  41. package/src/context/cli-options.js +88 -0
  42. package/src/context/score.js +234 -0
  43. package/src/context/sections.js +274 -0
  44. package/src/embed/interface.js +160 -0
  45. package/src/embed/openai.js +715 -0
  46. package/src/embed/prepare.js +182 -0
  47. package/src/embed/units.js +96 -0
  48. package/src/error-details.js +53 -0
  49. package/src/git-source.js +112 -52
  50. package/src/graph.js +95 -37
  51. package/src/http-server.js +36 -17
  52. package/src/index.js +15 -0
  53. package/src/indexer/assemble.js +566 -0
  54. package/src/indexer/build.js +290 -0
  55. package/src/indexer/cache.js +81 -0
  56. package/src/indexer/edges.js +430 -0
  57. package/src/indexer/index.js +44 -0
  58. package/src/indexer/paths.js +178 -0
  59. package/src/indexer/resolve.js +282 -0
  60. package/src/indexer/update.js +720 -0
  61. package/src/indexer.js +3 -1068
  62. package/src/live-authoring.js +4 -2329
  63. package/src/markdown.js +21 -16
  64. package/src/mcp/auth.js +409 -0
  65. package/src/mcp/http.js +317 -0
  66. package/src/mcp/principal.js +59 -0
  67. package/src/mcp/registry.js +356 -0
  68. package/src/mcp/resources.js +45 -0
  69. package/src/mcp/server.js +567 -0
  70. package/src/mcp/tools/catalog.js +247 -0
  71. package/src/mcp/tools/computation.js +83 -0
  72. package/src/mcp/tools/context.js +133 -0
  73. package/src/mcp/tools/graph.js +167 -0
  74. package/src/mcp/tools/live-authoring.js +316 -0
  75. package/src/mcp/tools/migration.js +86 -0
  76. package/src/mcp/tools/producers.js +79 -0
  77. package/src/mcp/tools/proposals.js +225 -0
  78. package/src/mcp/tools/provenance.js +87 -0
  79. package/src/mcp/tools/remote.js +79 -0
  80. package/src/mcp/tools/search.js +242 -0
  81. package/src/mcp-server.js +3 -1611
  82. package/src/migration.js +431 -253
  83. package/src/parser.js +245 -130
  84. package/src/plugins.js +71 -48
  85. package/src/policy/write-policy.js +713 -0
  86. package/src/producer-publisher.js +202 -78
  87. package/src/producers.js +311 -103
  88. package/src/project.js +346 -93
  89. package/src/remote.js +96 -61
  90. package/src/search/cli-options.js +107 -0
  91. package/src/search/confidence.js +61 -0
  92. package/src/search/dense.js +304 -0
  93. package/src/search/embedding-cli.js +57 -0
  94. package/src/search/embedding-config.js +217 -0
  95. package/src/search/fusion.js +249 -0
  96. package/src/search/hybrid.js +526 -0
  97. package/src/search/languages.js +200 -0
  98. package/src/search/lexical.js +695 -0
  99. package/src/search/query.js +620 -0
  100. package/src/search/stem/among.js +43 -0
  101. package/src/search/stem/base-stemmer.js +311 -0
  102. package/src/search/stem/en-regions.js +456 -0
  103. package/src/search/stem/en-suffixes.js +664 -0
  104. package/src/search/stem/en-tables.js +176 -0
  105. package/src/search/stem/en.js +238 -0
  106. package/src/search/stem/it-regions.js +459 -0
  107. package/src/search/stem/it-suffixes.js +471 -0
  108. package/src/search/stem/it-tables.js +257 -0
  109. package/src/search/stem/it.js +155 -0
  110. package/src/search-index.js +2 -81
  111. package/src/search.js +2 -252
  112. package/src/store.js +134 -81
  113. package/src/tool-packs.js +346 -0
  114. package/src/v02.js +301 -105
  115. package/src/validation.js +24 -20
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+
3
+ const { MAX_CHANGES, MAX_COMMIT_MESSAGE_BYTES } = require("../../live-authoring");
4
+ const {
5
+ DESTRUCTIVE_WRITE,
6
+ GATES,
7
+ READ_ONLY,
8
+ collectionPatchParameter,
9
+ defineTool,
10
+ detailParameter,
11
+ expectedToolOperation,
12
+ jsonContent,
13
+ nonEmptyStringParameter,
14
+ objectParameter,
15
+ optionalBooleanParameter,
16
+ relationParameter,
17
+ sourceParameter,
18
+ stringArrayParameter,
19
+ stringParameter,
20
+ writeContext,
21
+ } = require("../registry");
22
+
23
+ const LIVE_CREATE_CHANGE = {
24
+ type: "object",
25
+ additionalProperties: false,
26
+ properties: {
27
+ op: { type: "string", const: "create", description: "Create a new concept." },
28
+ path: nonEmptyStringParameter(
29
+ "Optional safe bundle-relative Markdown path; derived from type and title when omitted.",
30
+ ),
31
+ type: nonEmptyStringParameter("Concept type."),
32
+ title: nonEmptyStringParameter("Concept title."),
33
+ description: stringParameter("Optional concept description."),
34
+ body: stringParameter("Optional Markdown body; defaults to an H1 using the title."),
35
+ tags: stringArrayParameter("Initial tags.", { nonEmptyItems: true }),
36
+ sources: {
37
+ type: "array",
38
+ description: "Initial source resources or structured source entries.",
39
+ items: sourceParameter("Source entry."),
40
+ },
41
+ relations: {
42
+ type: "array",
43
+ description: "Initial typed relationships.",
44
+ items: relationParameter("Typed relation."),
45
+ },
46
+ metadata: objectParameter(
47
+ "Optional extension frontmatter; managed concept fields are rejected.",
48
+ ),
49
+ },
50
+ required: ["op", "type", "title"],
51
+ };
52
+
53
+ const LIVE_UPDATE_CHANGE = {
54
+ type: "object",
55
+ additionalProperties: false,
56
+ minProperties: 3,
57
+ properties: {
58
+ op: { type: "string", const: "update", description: "Update an existing concept in place." },
59
+ uri: nonEmptyStringParameter("Canonical or compatible URI of the existing concept."),
60
+ title: nonEmptyStringParameter("Replacement title."),
61
+ description: stringParameter("Replacement description."),
62
+ body: stringParameter("Replacement Markdown body."),
63
+ tags: collectionPatchParameter(
64
+ "Tags to add and/or remove; additions win when a tag appears in both lists.",
65
+ nonEmptyStringParameter("Tag."),
66
+ ),
67
+ sources: collectionPatchParameter(
68
+ "Sources to add/replace and/or remove by id or resource.",
69
+ sourceParameter("Source entry or selector."),
70
+ ),
71
+ relations: collectionPatchParameter(
72
+ "Relations to add/replace and/or remove by exact type plus target.",
73
+ relationParameter("Typed relation."),
74
+ ),
75
+ metadata: objectParameter(
76
+ "Extension frontmatter fields to add or replace; managed fields are rejected.",
77
+ ),
78
+ removeMetadataKeys: stringArrayParameter(
79
+ "Extension frontmatter keys to remove; managed fields are rejected.",
80
+ { nonEmptyItems: true },
81
+ ),
82
+ },
83
+ required: ["op", "uri"],
84
+ };
85
+
86
+ const LIVE_CHANGES_DESCRIPTION = [
87
+ `One through ${MAX_CHANGES} concept create or update operations handled as one batch.`,
88
+ "Create grammar: { op: 'create', type, title, path?, description?, body?, tags?: string[], sources?: (string | structured source object)[], relations?: { type, target, label?, description? }[], metadata?: object }.",
89
+ "Update grammar: { op: 'update', uri, title?, description?, body?, tags?: { add?: string[], remove?: string[] }, sources?: { add?: (string | source object)[], remove?: (string | { id } | { resource })[] }, relations?: { add?: relation[], remove?: relation[] }, metadata?, removeMetadataKeys? }; relation = { type, target, label?, description? }; include at least one update field.",
90
+ ].join(" ");
91
+
92
+ const LIVE_CHANGE_TOOL_PROPERTIES = {
93
+ bundle: nonEmptyStringParameter(
94
+ "Writable bundle id; optional when exactly one local root is configured.",
95
+ ),
96
+ detail: detailParameter(
97
+ "Receipt detail level; compact removes repeated planning fields while full preserves the v0.7 receipt layout.",
98
+ ),
99
+ message: stringParameter("Optional Git commit summary when automatic commits are enabled.", {
100
+ maxLength: MAX_COMMIT_MESSAGE_BYTES,
101
+ }),
102
+ changes: {
103
+ type: "array",
104
+ description: LIVE_CHANGES_DESCRIPTION,
105
+ minItems: 1,
106
+ maxItems: MAX_CHANGES,
107
+ items: { oneOf: [LIVE_CREATE_CHANGE, LIVE_UPDATE_CHANGE] },
108
+ },
109
+ };
110
+
111
+ const LIVE_CHANGE_EFFECTS_OUTPUT = {
112
+ type: "object",
113
+ description: "Compact structured summary of the fields changed by this operation.",
114
+ additionalProperties: true,
115
+ properties: {
116
+ changedFields: stringArrayParameter(
117
+ "Substantive concept fields changed, excluding server-managed generation provenance.",
118
+ ),
119
+ bodyChanged: optionalBooleanParameter("Whether the Markdown body changed."),
120
+ tags: objectParameter("Tags added and removed by the operation."),
121
+ sources: objectParameter("Sources added and removed by the operation."),
122
+ relations: objectParameter(
123
+ "Added, removed, and updated relation values as structured { type, target, label?, description? } objects.",
124
+ ),
125
+ metadata: objectParameter("Metadata fields set and removed by the operation."),
126
+ },
127
+ };
128
+
129
+ const LIVE_CHANGE_SUMMARY_OUTPUT = {
130
+ type: "object",
131
+ description: "Compact receipt for one validated or applied concept operation.",
132
+ additionalProperties: true,
133
+ properties: {
134
+ op: stringParameter("Operation kind."),
135
+ bundle: stringParameter("Target bundle id."),
136
+ path: stringParameter("Bundle-relative concept path."),
137
+ absolutePath: stringParameter("Absolute target concept filename."),
138
+ uri: stringParameter("Canonical concept URI."),
139
+ title: stringParameter("Resulting concept title."),
140
+ baseRevision: {
141
+ description: "Source revision before the operation; null for creates.",
142
+ oneOf: [{ type: "string" }, { type: "null" }],
143
+ },
144
+ candidateRevision: stringParameter("Revision of the validated candidate bytes."),
145
+ effects: LIVE_CHANGE_EFFECTS_OUTPUT,
146
+ },
147
+ };
148
+
149
+ const LIVE_CHANGE_OUTPUT_PROPERTIES = {
150
+ status: stringParameter("Validation or application outcome."),
151
+ readyToApply: optionalBooleanParameter(
152
+ "Whether policy, graph, revision, and configured Git preconditions currently allow apply.",
153
+ ),
154
+ filesChanged: optionalBooleanParameter(
155
+ "Whether filesystem changes remain when the request returns.",
156
+ ),
157
+ snapshot: objectParameter("Full-receipt time-of-check metadata for this planning result."),
158
+ preconditions: objectParameter(
159
+ "Full-receipt revision and Git preconditions checked for the batch.",
160
+ ),
161
+ generated: objectParameter("Server-owned generation actor and timestamp."),
162
+ target: objectParameter("Absolute bundle, repository, and affected-file locations."),
163
+ durability: objectParameter("Working-tree and automatic-commit durability state."),
164
+ changes: {
165
+ type: "array",
166
+ description: "Compact operation receipts.",
167
+ items: LIVE_CHANGE_SUMMARY_OUTPUT,
168
+ },
169
+ validation: objectParameter("Complete future-graph validation result."),
170
+ policyViolations: {
171
+ type: "array",
172
+ description:
173
+ "Write policy violations for this batch; present only when the server enforces a write policy (writePolicy in okf.project.yaml, or --policy with --root) and empty when the batch complies. Items: { code: 'policy_violation', rule: rule name or index (null when the default effect decided), reason: actor_denied | bundle_denied | path_denied | type_denied | missing_required_field | batch_too_large, field?, path?, bundleId?, uri?, limit?, count? }. Each violation also appears in validation.diagnostics with layer 'policy'. Any violation makes the batch invalid and apply refuses it before staging or touching disk.",
174
+ items: objectParameter("One structured write policy violation."),
175
+ },
176
+ git: objectParameter("Git policy and commit result."),
177
+ };
178
+
179
+ const LIVE_VALIDATE_OUTPUT = {
180
+ type: "object",
181
+ description: "Read-only validation receipt for a structured concept batch.",
182
+ additionalProperties: true,
183
+ properties: Object.assign(
184
+ {
185
+ valid: optionalBooleanParameter(
186
+ "Whether authoring policy and the complete future graph are valid, independent of transient Git readiness.",
187
+ ),
188
+ },
189
+ LIVE_CHANGE_OUTPUT_PROPERTIES,
190
+ ),
191
+ };
192
+
193
+ const LIVE_APPLY_OUTPUT = {
194
+ type: "object",
195
+ description:
196
+ "Application, target, durability, and validation receipt for a structured concept batch.",
197
+ additionalProperties: true,
198
+ properties: Object.assign(
199
+ {
200
+ applied: optionalBooleanParameter("Whether the complete batch was applied."),
201
+ },
202
+ LIVE_CHANGE_OUTPUT_PROPERTIES,
203
+ ),
204
+ };
205
+
206
+ function liveRequest(args) {
207
+ const input = Object.assign({}, args || {});
208
+ const detail = input.detail || "compact";
209
+ delete input.detail;
210
+ return { input, detail };
211
+ }
212
+
213
+ function projectLiveReceipt(receipt, detail) {
214
+ if (detail === "full") return receipt;
215
+ const compact = structuredClone(receipt);
216
+ const preconditionGit = compact.preconditions?.git;
217
+ if (preconditionGit || compact.git) {
218
+ compact.git = Object.assign({}, preconditionGit || {}, compact.git || {});
219
+ }
220
+ delete compact.snapshot;
221
+ delete compact.preconditions;
222
+ if (compact.target) delete compact.target.absolutePaths;
223
+ if (compact.durability) delete compact.durability.filesChanged;
224
+ (compact.changes || []).forEach((change) => {
225
+ delete change.bundle;
226
+ const effects = change.effects;
227
+ if (!effects) return;
228
+ for (const key of ["beforeRevision", "afterRevision", "bytesBefore", "bytesAfter"]) {
229
+ delete effects[key];
230
+ }
231
+ if (effects.bodyChanged === false) delete effects.bodyChanged;
232
+ ["tags", "sources", "relations", "metadata"].forEach((name) => {
233
+ const group = effects[name];
234
+ if (!group) return;
235
+ Object.keys(group).forEach((key) => {
236
+ const list = group[key];
237
+ if (!list || !Array.isArray(list.values)) return;
238
+ if (!list.omitted) delete list.omitted;
239
+ if (!list.values.length && !list.omitted) delete group[key];
240
+ });
241
+ if (!Object.keys(group).length) delete effects[name];
242
+ });
243
+ });
244
+ return compact;
245
+ }
246
+
247
+ function requireLiveAuthoring(state) {
248
+ if (!state.allowWrite || !state.liveAuthoringService) {
249
+ throw new Error(
250
+ "Live OKF authoring is not configured. Start the server with --write and --actor.",
251
+ );
252
+ }
253
+ return state.liveAuthoringService;
254
+ }
255
+
256
+ const tools = {
257
+ okf_validate_changes: {
258
+ ...defineTool(
259
+ "Validate a complete structured concept create or update batch without changing files; write policy violations are reported read-only alongside graph validation.",
260
+ READ_ONLY,
261
+ LIVE_CHANGE_TOOL_PROPERTIES,
262
+ ["changes"],
263
+ undefined,
264
+ LIVE_VALIDATE_OUTPUT,
265
+ ),
266
+ enabled: GATES.liveWrite,
267
+ handler: async (state, args, principal) => {
268
+ const request = liveRequest(args);
269
+ const result = await expectedToolOperation(
270
+ () =>
271
+ requireLiveAuthoring(state).validateChanges(
272
+ request.input,
273
+ writeContext(state, principal),
274
+ ),
275
+ { translateTypeError: true },
276
+ );
277
+ if (result.applied || result.filesChanged) {
278
+ state.rebuildIndex();
279
+ }
280
+ return jsonContent(projectLiveReceipt(result, request.detail), { structured: true });
281
+ },
282
+ },
283
+ okf_apply_changes: {
284
+ ...defineTool(
285
+ "Validate and apply one or more structured concept creates or updates to one local bundle as one batch; a batch that violates the configured write policy is refused before any file is touched.",
286
+ DESTRUCTIVE_WRITE,
287
+ LIVE_CHANGE_TOOL_PROPERTIES,
288
+ ["changes"],
289
+ undefined,
290
+ LIVE_APPLY_OUTPUT,
291
+ ),
292
+ enabled: GATES.liveWrite,
293
+ handler: async (state, args, principal) => {
294
+ const request = liveRequest(args);
295
+ const result = await expectedToolOperation(
296
+ () =>
297
+ requireLiveAuthoring(state).applyChanges(request.input, writeContext(state, principal)),
298
+ { translateTypeError: true },
299
+ );
300
+ if (result.applied || result.filesChanged) {
301
+ const previous = state.index;
302
+ state.rebuildIndex();
303
+ // WP3c: embed only the batch's changed units, after the writer lock.
304
+ if (result.applied && state.embeddings) {
305
+ result.embedding = await state.embeddings.embedChanged(previous, state.index);
306
+ }
307
+ }
308
+ return jsonContent(projectLiveReceipt(result, request.detail), {
309
+ structured: true,
310
+ isError: result.applied === false,
311
+ });
312
+ },
313
+ },
314
+ };
315
+
316
+ module.exports = { tools };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ const { checkV02Migration } = require("../../migration");
4
+ const {
5
+ GATES,
6
+ LOCAL_WRITE,
7
+ READ_ONLY,
8
+ ToolExecutionError,
9
+ defineTool,
10
+ expectedToolOperation,
11
+ jsonContent,
12
+ nonEmptyStringParameter,
13
+ objectParameter,
14
+ requireAuthoring,
15
+ stringArrayParameter,
16
+ stringParameter,
17
+ } = require("../registry");
18
+
19
+ const tools = {
20
+ check_v02_migration: {
21
+ ...defineTool(
22
+ "Analyze a local or remote bundle for safe staged OKF v0.2 migration without creating proposals or writes.",
23
+ READ_ONLY,
24
+ {
25
+ bundle: nonEmptyStringParameter(
26
+ "Bundle id to analyze; optional when exactly one root is loaded.",
27
+ ),
28
+ actorMappings: objectParameter(
29
+ "Mappings keyed by URI, path, or $default; each value requires by plus confirmed: true.",
30
+ ),
31
+ generatedPaths: stringArrayParameter(
32
+ "Paths generated elsewhere and therefore skipped from direct proposals.",
33
+ { nonEmptyItems: true },
34
+ ),
35
+ },
36
+ [],
37
+ ),
38
+ handler: async (state, args) => {
39
+ const index = state.index;
40
+ const bundleId = args.bundle || (index.bundles.length === 1 ? index.bundles[0].id : "");
41
+ if (!bundleId) {
42
+ throw new ToolExecutionError(
43
+ "A bundle id is required when more than one OKF root is loaded.",
44
+ );
45
+ }
46
+ if (!index.bundles.some((bundle) => bundle.id === bundleId)) {
47
+ throw new ToolExecutionError(`Unknown OKF bundle: ${bundleId}`);
48
+ }
49
+ return jsonContent(
50
+ await expectedToolOperation(
51
+ () => checkV02Migration(index, Object.assign({}, args, { bundle: bundleId })),
52
+ { translateTypeError: true },
53
+ ),
54
+ );
55
+ },
56
+ },
57
+ okf_propose_v02_migration: {
58
+ ...defineTool(
59
+ "Create a review-only Stage-A migration manifest plus individual child proposals; never accept them automatically.",
60
+ LOCAL_WRITE,
61
+ {
62
+ bundle: nonEmptyStringParameter(
63
+ "Writable root id; optional when exactly one local root is configured.",
64
+ ),
65
+ actorMappings: objectParameter(
66
+ "Mappings keyed by URI, path, or $default; each value requires by plus confirmed: true.",
67
+ ),
68
+ generatedPaths: stringArrayParameter(
69
+ "Generated concept paths that must be migrated through their generator.",
70
+ { nonEmptyItems: true },
71
+ ),
72
+ message: stringParameter("Optional migration review note."),
73
+ },
74
+ [],
75
+ ),
76
+ enabled: GATES.authoringMutation,
77
+ handler: async (state, args, principal) => {
78
+ const result = await expectedToolOperation(() =>
79
+ requireAuthoring(state, principal).proposeV02Migration(args),
80
+ );
81
+ return jsonContent(result, { isError: result.created === false });
82
+ },
83
+ },
84
+ };
85
+
86
+ module.exports = { tools };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ const { producerReceipt } = require("../../producers");
4
+ const {
5
+ GATES,
6
+ PRODUCER_PREVIEW,
7
+ PRODUCER_RUN,
8
+ READ_ONLY,
9
+ defineTool,
10
+ detailParameter,
11
+ expectedToolOperation,
12
+ jsonContent,
13
+ nonEmptyStringParameter,
14
+ } = require("../registry");
15
+
16
+ const tools = {
17
+ okf_list_producers: {
18
+ ...defineTool(
19
+ "List configured producer instances without loading or executing their packages.",
20
+ READ_ONLY,
21
+ ),
22
+ enabled: GATES.producer,
23
+ handler: (state) => jsonContent(state.producerService.list(), { structured: true }),
24
+ },
25
+ okf_preview_producer: {
26
+ ...defineTool(
27
+ "Read source metadata, generate a candidate OKF 0.2 bundle, and validate its publication diff without writing files.",
28
+ PRODUCER_PREVIEW,
29
+ {
30
+ producer: nonEmptyStringParameter("Configured producer instance name."),
31
+ detail: detailParameter(
32
+ "Receipt detail level; full includes bounded bundle-relative changed paths.",
33
+ ),
34
+ },
35
+ ["producer"],
36
+ ),
37
+ enabled: GATES.producer,
38
+ handler: async (state, args) => {
39
+ const result = await expectedToolOperation(
40
+ () =>
41
+ state.producerService.preview(args.producer, {
42
+ additionalBundles: state.remoteBundles,
43
+ }),
44
+ { translateTypeError: true },
45
+ );
46
+ return jsonContent(producerReceipt(result, args.detail || "compact"), { structured: true });
47
+ },
48
+ },
49
+ okf_run_producer: {
50
+ ...defineTool(
51
+ "Regenerate, strictly validate, safely publish, and reindex one configured OKF producer.",
52
+ PRODUCER_RUN,
53
+ {
54
+ producer: nonEmptyStringParameter("Configured producer instance name."),
55
+ detail: detailParameter(
56
+ "Receipt detail level; full includes bounded bundle-relative changed paths.",
57
+ ),
58
+ },
59
+ ["producer"],
60
+ ),
61
+ enabled: GATES.producerWrite,
62
+ handler: async (state, args) => {
63
+ const result = await expectedToolOperation(
64
+ () =>
65
+ state.producerService.run(args.producer, {
66
+ additionalBundles: state.remoteBundles,
67
+ }),
68
+ { translateTypeError: true },
69
+ );
70
+ if (result.applied) state.rebuildIndex();
71
+ return jsonContent(producerReceipt(result, args.detail || "compact"), {
72
+ structured: true,
73
+ isError: result.applied === false,
74
+ });
75
+ },
76
+ },
77
+ };
78
+
79
+ module.exports = { tools };