@mfdaves/okf-mcp 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -17
- package/okf/bundles/okf-mcp/interfaces/mcp-tools.md +12 -2
- package/okf/bundles/okf-mcp/policies/authoring-safety.md +14 -2
- package/okf/bundles/okf-mcp/runtime/file-concept-store.md +4 -2
- package/okf/bundles/okf-mcp/runtime/mcp-server.md +2 -2
- package/okf/bundles/okf-mcp/specs/git-sources.md +1 -1
- package/okf/bundles/okf-mcp/workflows/concept-authoring.md +9 -3
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/authoring.js +77 -11
- package/src/cli.js +62 -1
- package/src/git-source.js +13 -4
- package/src/index.js +1 -0
- package/src/indexer.js +40 -6
- package/src/live-authoring.js +2249 -0
- package/src/mcp-server.js +299 -9
- package/src/store.js +10 -1
- package/src/v02.js +1 -0
package/src/mcp-server.js
CHANGED
|
@@ -22,6 +22,11 @@ const { MAX_QUERY_CHARACTERS, MAX_QUERY_TERMS } = require("./search-index");
|
|
|
22
22
|
const { exportGraph, findPaths, getGraph, getNeighbors, getSubgraph, graphSummary } = require("./graph");
|
|
23
23
|
const { fetchGitHubBundle, fetchRemoteBundles, sanitizeRemoteId } = require("./remote");
|
|
24
24
|
const { ConceptAuthoringService } = require("./authoring");
|
|
25
|
+
const {
|
|
26
|
+
LiveAuthoringService,
|
|
27
|
+
MAX_CHANGES,
|
|
28
|
+
MAX_COMMIT_MESSAGE_BYTES,
|
|
29
|
+
} = require("./live-authoring");
|
|
25
30
|
const { FileConceptStore } = require("./store");
|
|
26
31
|
const { loadProjectConfig } = require("./project");
|
|
27
32
|
const {
|
|
@@ -38,9 +43,15 @@ const packageMetadata = require("../package.json");
|
|
|
38
43
|
const MAX_MCP_MESSAGE_BYTES = 1024 * 1024;
|
|
39
44
|
|
|
40
45
|
class ToolExecutionError extends Error {
|
|
41
|
-
constructor(message) {
|
|
46
|
+
constructor(message, code, details) {
|
|
42
47
|
super(message);
|
|
43
48
|
this.name = "ToolExecutionError";
|
|
49
|
+
if (typeof code === "string" && code) {
|
|
50
|
+
this.code = code;
|
|
51
|
+
}
|
|
52
|
+
if (details !== undefined) {
|
|
53
|
+
this.details = details;
|
|
54
|
+
}
|
|
44
55
|
}
|
|
45
56
|
}
|
|
46
57
|
|
|
@@ -116,7 +127,183 @@ function objectParameter(description, extra) {
|
|
|
116
127
|
}, extra || {});
|
|
117
128
|
}
|
|
118
129
|
|
|
119
|
-
function
|
|
130
|
+
function relationParameter(description) {
|
|
131
|
+
return {
|
|
132
|
+
type: "object",
|
|
133
|
+
description,
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
properties: {
|
|
136
|
+
type: nonEmptyStringParameter("Typed relation name."),
|
|
137
|
+
target: nonEmptyStringParameter("Relation target URI or bundle-local path."),
|
|
138
|
+
label: stringParameter("Optional human-readable relation label."),
|
|
139
|
+
description: stringParameter("Optional relation explanation."),
|
|
140
|
+
},
|
|
141
|
+
required: ["type", "target"],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sourceParameter(description) {
|
|
146
|
+
return {
|
|
147
|
+
description,
|
|
148
|
+
anyOf: [
|
|
149
|
+
nonEmptyStringParameter("Source resource URI or bundle-local path."),
|
|
150
|
+
objectParameter("Structured OKF source entry."),
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function collectionPatchParameter(description, item) {
|
|
156
|
+
return {
|
|
157
|
+
type: "object",
|
|
158
|
+
description,
|
|
159
|
+
additionalProperties: false,
|
|
160
|
+
minProperties: 1,
|
|
161
|
+
properties: {
|
|
162
|
+
add: { type: "array", items: item },
|
|
163
|
+
remove: { type: "array", items: item },
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const LIVE_CREATE_CHANGE = {
|
|
169
|
+
type: "object",
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
properties: {
|
|
172
|
+
op: { type: "string", const: "create", description: "Create a new concept." },
|
|
173
|
+
path: nonEmptyStringParameter("Optional safe bundle-relative Markdown path; derived from type and title when omitted."),
|
|
174
|
+
type: nonEmptyStringParameter("Concept type."),
|
|
175
|
+
title: nonEmptyStringParameter("Concept title."),
|
|
176
|
+
description: stringParameter("Optional concept description."),
|
|
177
|
+
body: stringParameter("Optional Markdown body; defaults to an H1 using the title."),
|
|
178
|
+
tags: stringArrayParameter("Initial tags.", { nonEmptyItems: true }),
|
|
179
|
+
sources: {
|
|
180
|
+
type: "array",
|
|
181
|
+
description: "Initial source resources or structured source entries.",
|
|
182
|
+
items: sourceParameter("Source entry."),
|
|
183
|
+
},
|
|
184
|
+
relations: {
|
|
185
|
+
type: "array",
|
|
186
|
+
description: "Initial typed relationships.",
|
|
187
|
+
items: relationParameter("Typed relation."),
|
|
188
|
+
},
|
|
189
|
+
metadata: objectParameter("Optional extension frontmatter; managed concept fields are rejected."),
|
|
190
|
+
},
|
|
191
|
+
required: ["op", "type", "title"],
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const LIVE_UPDATE_CHANGE = {
|
|
195
|
+
type: "object",
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
minProperties: 3,
|
|
198
|
+
properties: {
|
|
199
|
+
op: { type: "string", const: "update", description: "Update an existing concept in place." },
|
|
200
|
+
uri: nonEmptyStringParameter("Canonical or compatible URI of the existing concept."),
|
|
201
|
+
title: nonEmptyStringParameter("Replacement title."),
|
|
202
|
+
description: stringParameter("Replacement description."),
|
|
203
|
+
body: stringParameter("Replacement Markdown body."),
|
|
204
|
+
tags: collectionPatchParameter(
|
|
205
|
+
"Tags to add and/or remove; additions win when a tag appears in both lists.",
|
|
206
|
+
nonEmptyStringParameter("Tag."),
|
|
207
|
+
),
|
|
208
|
+
sources: collectionPatchParameter(
|
|
209
|
+
"Sources to add/replace and/or remove by id or resource.",
|
|
210
|
+
sourceParameter("Source entry or selector."),
|
|
211
|
+
),
|
|
212
|
+
relations: collectionPatchParameter(
|
|
213
|
+
"Relations to add/replace and/or remove by exact type plus target.",
|
|
214
|
+
relationParameter("Typed relation."),
|
|
215
|
+
),
|
|
216
|
+
metadata: objectParameter("Extension frontmatter fields to add or replace; managed fields are rejected."),
|
|
217
|
+
removeMetadataKeys: stringArrayParameter("Extension frontmatter keys to remove; managed fields are rejected.", { nonEmptyItems: true }),
|
|
218
|
+
},
|
|
219
|
+
required: ["op", "uri"],
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const LIVE_CHANGES_DESCRIPTION = [
|
|
223
|
+
`One through ${MAX_CHANGES} concept create or update operations handled as one batch.`,
|
|
224
|
+
"Create grammar: { op: 'create', type, title, path?, description?, body?, tags?: string[], sources?: (string | structured source object)[], relations?: { type, target, label?, description? }[], metadata?: object }.",
|
|
225
|
+
"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.",
|
|
226
|
+
].join(" ");
|
|
227
|
+
|
|
228
|
+
const LIVE_CHANGE_TOOL_PROPERTIES = {
|
|
229
|
+
bundle: nonEmptyStringParameter("Writable bundle id; optional when exactly one local root is configured."),
|
|
230
|
+
message: stringParameter("Optional Git commit summary when automatic commits are enabled.", {
|
|
231
|
+
maxLength: MAX_COMMIT_MESSAGE_BYTES,
|
|
232
|
+
}),
|
|
233
|
+
changes: {
|
|
234
|
+
type: "array",
|
|
235
|
+
description: LIVE_CHANGES_DESCRIPTION,
|
|
236
|
+
minItems: 1,
|
|
237
|
+
maxItems: MAX_CHANGES,
|
|
238
|
+
items: { oneOf: [LIVE_CREATE_CHANGE, LIVE_UPDATE_CHANGE] },
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const LIVE_CHANGE_EFFECTS_OUTPUT = {
|
|
243
|
+
type: "object",
|
|
244
|
+
description: "Compact structured summary of the fields changed by this operation.",
|
|
245
|
+
additionalProperties: true,
|
|
246
|
+
properties: {
|
|
247
|
+
bodyChanged: optionalBooleanParameter("Whether the Markdown body changed."),
|
|
248
|
+
tags: objectParameter("Tags added and removed by the operation."),
|
|
249
|
+
sources: objectParameter("Sources added and removed by the operation."),
|
|
250
|
+
relations: objectParameter("Relations added and removed by the operation."),
|
|
251
|
+
metadata: objectParameter("Metadata fields set and removed by the operation."),
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const LIVE_CHANGE_SUMMARY_OUTPUT = {
|
|
256
|
+
type: "object",
|
|
257
|
+
description: "Compact receipt for one validated or applied concept operation.",
|
|
258
|
+
additionalProperties: true,
|
|
259
|
+
properties: {
|
|
260
|
+
op: stringParameter("Operation kind."),
|
|
261
|
+
bundle: stringParameter("Target bundle id."),
|
|
262
|
+
path: stringParameter("Bundle-relative concept path."),
|
|
263
|
+
absolutePath: stringParameter("Absolute target concept filename."),
|
|
264
|
+
uri: stringParameter("Canonical concept URI."),
|
|
265
|
+
title: stringParameter("Resulting concept title."),
|
|
266
|
+
effects: LIVE_CHANGE_EFFECTS_OUTPUT,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const LIVE_CHANGE_OUTPUT_PROPERTIES = {
|
|
271
|
+
status: stringParameter("Validation or application outcome."),
|
|
272
|
+
readyToApply: optionalBooleanParameter("Whether policy, graph, revision, and configured Git preconditions currently allow apply."),
|
|
273
|
+
filesChanged: optionalBooleanParameter("Whether filesystem changes remain when the request returns."),
|
|
274
|
+
snapshot: objectParameter("Time-of-check metadata for this planning result."),
|
|
275
|
+
preconditions: objectParameter("Revision and Git preconditions checked for the batch."),
|
|
276
|
+
generated: objectParameter("Server-owned generation actor and timestamp."),
|
|
277
|
+
target: objectParameter("Absolute bundle, repository, and affected-file locations."),
|
|
278
|
+
durability: objectParameter("Working-tree and automatic-commit durability state."),
|
|
279
|
+
changes: {
|
|
280
|
+
type: "array",
|
|
281
|
+
description: "Compact operation receipts.",
|
|
282
|
+
items: LIVE_CHANGE_SUMMARY_OUTPUT,
|
|
283
|
+
},
|
|
284
|
+
validation: objectParameter("Complete future-graph validation result."),
|
|
285
|
+
git: objectParameter("Git policy and commit result."),
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const LIVE_VALIDATE_OUTPUT = {
|
|
289
|
+
type: "object",
|
|
290
|
+
description: "Read-only validation receipt for a structured concept batch.",
|
|
291
|
+
additionalProperties: true,
|
|
292
|
+
properties: Object.assign({
|
|
293
|
+
valid: optionalBooleanParameter("Whether authoring policy and the complete future graph are valid, independent of transient Git readiness."),
|
|
294
|
+
}, LIVE_CHANGE_OUTPUT_PROPERTIES),
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const LIVE_APPLY_OUTPUT = {
|
|
298
|
+
type: "object",
|
|
299
|
+
description: "Application, target, durability, and validation receipt for a structured concept batch.",
|
|
300
|
+
additionalProperties: true,
|
|
301
|
+
properties: Object.assign({
|
|
302
|
+
applied: optionalBooleanParameter("Whether the complete batch was applied."),
|
|
303
|
+
}, LIVE_CHANGE_OUTPUT_PROPERTIES),
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
function defineTool(description, annotations, properties, required, schemaExtras, outputSchema) {
|
|
120
307
|
return {
|
|
121
308
|
description,
|
|
122
309
|
annotations,
|
|
@@ -127,6 +314,7 @@ function defineTool(description, annotations, properties, required, schemaExtras
|
|
|
127
314
|
...(required && required.length ? { required } : {}),
|
|
128
315
|
...(schemaExtras || {}),
|
|
129
316
|
},
|
|
317
|
+
...(outputSchema ? { outputSchema } : {}),
|
|
130
318
|
};
|
|
131
319
|
}
|
|
132
320
|
|
|
@@ -412,6 +600,22 @@ const TOOL_DEFINITIONS = {
|
|
|
412
600
|
},
|
|
413
601
|
["proposalId"],
|
|
414
602
|
),
|
|
603
|
+
okf_validate_changes: defineTool(
|
|
604
|
+
"Validate a complete structured concept create or update batch without changing files.",
|
|
605
|
+
READ_ONLY,
|
|
606
|
+
LIVE_CHANGE_TOOL_PROPERTIES,
|
|
607
|
+
["changes"],
|
|
608
|
+
undefined,
|
|
609
|
+
LIVE_VALIDATE_OUTPUT,
|
|
610
|
+
),
|
|
611
|
+
okf_apply_changes: defineTool(
|
|
612
|
+
"Validate and apply one or more structured concept creates or updates to one local bundle as one batch.",
|
|
613
|
+
DESTRUCTIVE_WRITE,
|
|
614
|
+
LIVE_CHANGE_TOOL_PROPERTIES,
|
|
615
|
+
["changes"],
|
|
616
|
+
undefined,
|
|
617
|
+
LIVE_APPLY_OUTPUT,
|
|
618
|
+
),
|
|
415
619
|
get_graph: defineTool(
|
|
416
620
|
"Return a bounded set of OKF graph nodes and edges with optional concept filters.",
|
|
417
621
|
READ_ONLY,
|
|
@@ -513,6 +717,10 @@ const AUTHORING_MUTATION_TOOL_NAMES = new Set([
|
|
|
513
717
|
const COMPUTATION_AUTHORING_TOOL_NAMES = new Set([
|
|
514
718
|
"okf_propose_attested_computation",
|
|
515
719
|
]);
|
|
720
|
+
const LIVE_WRITE_TOOL_NAMES = new Set([
|
|
721
|
+
"okf_validate_changes",
|
|
722
|
+
"okf_apply_changes",
|
|
723
|
+
]);
|
|
516
724
|
const RUNTIME_REMOTE_TOOL_NAMES = new Set([
|
|
517
725
|
"load_remote_bundle",
|
|
518
726
|
]);
|
|
@@ -526,6 +734,9 @@ function jsonContent(value, options) {
|
|
|
526
734
|
},
|
|
527
735
|
],
|
|
528
736
|
};
|
|
737
|
+
if (options && options.structured) {
|
|
738
|
+
result.structuredContent = value;
|
|
739
|
+
}
|
|
529
740
|
if (options && options.isError) {
|
|
530
741
|
result.isError = true;
|
|
531
742
|
}
|
|
@@ -547,6 +758,9 @@ function toolEnabled(state, name) {
|
|
|
547
758
|
&& state.allowComputationAuthoring,
|
|
548
759
|
);
|
|
549
760
|
}
|
|
761
|
+
if (LIVE_WRITE_TOOL_NAMES.has(name)) {
|
|
762
|
+
return Boolean(state && state.allowWrite && state.liveAuthoringService);
|
|
763
|
+
}
|
|
550
764
|
if (RUNTIME_REMOTE_TOOL_NAMES.has(name)) {
|
|
551
765
|
return Boolean(state && state.allowRuntimeRemoteLoad);
|
|
552
766
|
}
|
|
@@ -572,7 +786,7 @@ function canonicalResourceUri(uri) {
|
|
|
572
786
|
}
|
|
573
787
|
}
|
|
574
788
|
|
|
575
|
-
function publicBundles(index) {
|
|
789
|
+
function publicBundles(index, options) {
|
|
576
790
|
return index.bundles.map((bundle) => {
|
|
577
791
|
const documentCount = index.documents.filter((doc) => doc.bundle === bundle.id).length;
|
|
578
792
|
const conceptCount = index.concepts.filter((doc) => doc.bundle === bundle.id).length;
|
|
@@ -596,12 +810,17 @@ function publicBundles(index) {
|
|
|
596
810
|
exclude: bundle.exclude || [],
|
|
597
811
|
};
|
|
598
812
|
}
|
|
599
|
-
const
|
|
600
|
-
|
|
813
|
+
const absoluteRoot = path.resolve(bundle.root);
|
|
814
|
+
const projectRoot = index.project && index.project.root
|
|
815
|
+
? path.resolve(index.project.root)
|
|
816
|
+
: null;
|
|
817
|
+
const root = projectRoot
|
|
818
|
+
? path.relative(projectRoot, absoluteRoot).replace(/\\/g, "/") || "."
|
|
601
819
|
: "<configured>";
|
|
602
820
|
return {
|
|
603
821
|
id: bundle.id,
|
|
604
822
|
root,
|
|
823
|
+
...((options && options.includeAbsolutePaths) ? { absoluteRoot, projectRoot } : {}),
|
|
605
824
|
documentCount,
|
|
606
825
|
conceptCount,
|
|
607
826
|
assetCount,
|
|
@@ -719,6 +938,13 @@ function requireAuthoring(state) {
|
|
|
719
938
|
return state.authoringService;
|
|
720
939
|
}
|
|
721
940
|
|
|
941
|
+
function requireLiveAuthoring(state) {
|
|
942
|
+
if (!state.allowWrite || !state.liveAuthoringService) {
|
|
943
|
+
throw new Error("Live OKF authoring is not configured. Start the server with --write and --actor.");
|
|
944
|
+
}
|
|
945
|
+
return state.liveAuthoringService;
|
|
946
|
+
}
|
|
947
|
+
|
|
722
948
|
function rebuildStateIndex(state) {
|
|
723
949
|
const index = buildIndex(
|
|
724
950
|
state.localBundleArgs.concat(state.remoteBundles),
|
|
@@ -746,7 +972,11 @@ async function expectedToolOperation(operation, options) {
|
|
|
746
972
|
if (programmingError) {
|
|
747
973
|
throw error;
|
|
748
974
|
}
|
|
749
|
-
throw new ToolExecutionError(
|
|
975
|
+
throw new ToolExecutionError(
|
|
976
|
+
error && error.message ? error.message : String(error),
|
|
977
|
+
error && error.code,
|
|
978
|
+
error && error.details,
|
|
979
|
+
);
|
|
750
980
|
}
|
|
751
981
|
}
|
|
752
982
|
|
|
@@ -763,7 +993,9 @@ async function callTool(state, name, args) {
|
|
|
763
993
|
try {
|
|
764
994
|
switch (name) {
|
|
765
995
|
case "list_bundles":
|
|
766
|
-
return jsonContent(publicBundles(index
|
|
996
|
+
return jsonContent(publicBundles(index, {
|
|
997
|
+
includeAbsolutePaths: Boolean(state.allowWrite),
|
|
998
|
+
}));
|
|
767
999
|
case "list_concepts":
|
|
768
1000
|
return jsonContent(listConcepts(index, args));
|
|
769
1001
|
case "get_concept":
|
|
@@ -912,6 +1144,33 @@ async function callTool(state, name, args) {
|
|
|
912
1144
|
return jsonContent(await expectedToolOperation(
|
|
913
1145
|
() => requireAuthoring(state).rejectProposal(args),
|
|
914
1146
|
));
|
|
1147
|
+
case "okf_validate_changes": {
|
|
1148
|
+
const result = await expectedToolOperation(
|
|
1149
|
+
() => requireLiveAuthoring(state).validateChanges(args, {
|
|
1150
|
+
additionalBundles: state.remoteBundles,
|
|
1151
|
+
}),
|
|
1152
|
+
{ translateTypeError: true },
|
|
1153
|
+
);
|
|
1154
|
+
if (result.applied || result.filesChanged) {
|
|
1155
|
+
rebuildStateIndex(state);
|
|
1156
|
+
}
|
|
1157
|
+
return jsonContent(result, { structured: true });
|
|
1158
|
+
}
|
|
1159
|
+
case "okf_apply_changes": {
|
|
1160
|
+
const result = await expectedToolOperation(
|
|
1161
|
+
() => requireLiveAuthoring(state).applyChanges(args, {
|
|
1162
|
+
additionalBundles: state.remoteBundles,
|
|
1163
|
+
}),
|
|
1164
|
+
{ translateTypeError: true },
|
|
1165
|
+
);
|
|
1166
|
+
if (result.applied || result.filesChanged) {
|
|
1167
|
+
rebuildStateIndex(state);
|
|
1168
|
+
}
|
|
1169
|
+
return jsonContent(result, {
|
|
1170
|
+
structured: true,
|
|
1171
|
+
isError: result.applied === false,
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
915
1174
|
case "get_graph":
|
|
916
1175
|
return jsonContent(getGraph(index, args));
|
|
917
1176
|
case "get_neighbors":
|
|
@@ -951,11 +1210,14 @@ async function callTool(state, name, args) {
|
|
|
951
1210
|
if (!(error instanceof ToolExecutionError)) {
|
|
952
1211
|
throw error;
|
|
953
1212
|
}
|
|
954
|
-
|
|
1213
|
+
const failure = {
|
|
955
1214
|
error: "Tool execution failed",
|
|
956
1215
|
tool: name,
|
|
957
1216
|
message: error.message,
|
|
958
|
-
|
|
1217
|
+
...(error.code ? { code: error.code } : {}),
|
|
1218
|
+
...(error.details !== undefined ? { details: error.details } : {}),
|
|
1219
|
+
};
|
|
1220
|
+
return jsonContent(failure, { isError: true, structured: true });
|
|
959
1221
|
}
|
|
960
1222
|
}
|
|
961
1223
|
|
|
@@ -994,6 +1256,8 @@ function createState(bundleArgs, options) {
|
|
|
994
1256
|
relationTypes,
|
|
995
1257
|
project,
|
|
996
1258
|
authoringService,
|
|
1259
|
+
liveAuthoringService: options && options.liveAuthoringService,
|
|
1260
|
+
allowWrite: Boolean(options && options.allowWrite),
|
|
997
1261
|
allowAuthoring: Boolean(options && options.allowAuthoring),
|
|
998
1262
|
allowRuntimeRemoteLoad: Boolean(options && options.allowRuntimeRemoteLoad),
|
|
999
1263
|
allowComputationAuthoring: Boolean(options && options.allowComputationAuthoring),
|
|
@@ -1012,6 +1276,9 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1012
1276
|
const localBundleArgs = (loaded.bundles || []).filter((bundle) => !bundle.remote);
|
|
1013
1277
|
const store = options.authoringStore || FileConceptStore.fromProject(options.projectPath, { proposalRoot: options.proposalRoot });
|
|
1014
1278
|
const authoringService = options.authoringService || new ConceptAuthoringService(store);
|
|
1279
|
+
const liveAuthoringService = options.liveAuthoringService || (options.allowWrite
|
|
1280
|
+
? new LiveAuthoringService(store, { actor: options.actor, gitCommit: options.gitCommit })
|
|
1281
|
+
: null);
|
|
1015
1282
|
const initialIndex = attachProject(
|
|
1016
1283
|
buildIndex(localBundleArgs.concat(initialRemoteBundles), {
|
|
1017
1284
|
relationTypes: loaded.project.relationTypes,
|
|
@@ -1024,6 +1291,8 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1024
1291
|
initialRemoteBundles,
|
|
1025
1292
|
relationTypes: loaded.project.relationTypes,
|
|
1026
1293
|
authoringService,
|
|
1294
|
+
liveAuthoringService,
|
|
1295
|
+
allowWrite: options.allowWrite,
|
|
1027
1296
|
allowAuthoring: options.allowAuthoring,
|
|
1028
1297
|
allowRuntimeRemoteLoad: options.allowRuntimeRemoteLoad,
|
|
1029
1298
|
allowComputationAuthoring: options.allowComputationAuthoring,
|
|
@@ -1037,6 +1306,9 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1037
1306
|
strictLinks: options.strictLinks,
|
|
1038
1307
|
});
|
|
1039
1308
|
const authoringService = options.authoringService || new ConceptAuthoringService(store);
|
|
1309
|
+
const liveAuthoringService = options.liveAuthoringService || (options.allowWrite
|
|
1310
|
+
? new LiveAuthoringService(store, { actor: options.actor, gitCommit: options.gitCommit })
|
|
1311
|
+
: null);
|
|
1040
1312
|
const localBundleArgs = store.getBundles();
|
|
1041
1313
|
const remoteBundles = await fetchRemoteBundles(options.remoteBundles || []);
|
|
1042
1314
|
const initialIndex = attachProject(buildIndex(localBundleArgs.concat(remoteBundles), {
|
|
@@ -1049,6 +1321,8 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1049
1321
|
initialRemoteBundles: remoteBundles,
|
|
1050
1322
|
relationTypes: store.getRelationTypes(),
|
|
1051
1323
|
authoringService,
|
|
1324
|
+
liveAuthoringService,
|
|
1325
|
+
allowWrite: options.allowWrite,
|
|
1052
1326
|
allowAuthoring: options.allowAuthoring,
|
|
1053
1327
|
allowRuntimeRemoteLoad: options.allowRuntimeRemoteLoad,
|
|
1054
1328
|
allowComputationAuthoring: options.allowComputationAuthoring,
|
|
@@ -1059,6 +1333,17 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1059
1333
|
}
|
|
1060
1334
|
const remoteBundles = await fetchRemoteBundles((options && options.remoteBundles) || []);
|
|
1061
1335
|
const localBundleArgs = (bundleArgs || []).slice();
|
|
1336
|
+
const liveAuthoringService = options && options.liveAuthoringService
|
|
1337
|
+
? options.liveAuthoringService
|
|
1338
|
+
: options && options.allowWrite && options.authoringService && options.authoringService.store
|
|
1339
|
+
? new LiveAuthoringService(options.authoringService.store, {
|
|
1340
|
+
actor: options.actor,
|
|
1341
|
+
gitCommit: options.gitCommit,
|
|
1342
|
+
})
|
|
1343
|
+
: null;
|
|
1344
|
+
if (options && options.allowWrite && !liveAuthoringService) {
|
|
1345
|
+
throw new Error("Live OKF authoring requires --root or --project and a configured actor.");
|
|
1346
|
+
}
|
|
1062
1347
|
return createState(localBundleArgs, {
|
|
1063
1348
|
initialIndex: buildIndex(localBundleArgs.concat(remoteBundles), {
|
|
1064
1349
|
strictLinks: options && options.strictLinks,
|
|
@@ -1066,6 +1351,8 @@ async function createStateAsync(bundleArgs, options) {
|
|
|
1066
1351
|
}),
|
|
1067
1352
|
initialRemoteBundles: remoteBundles,
|
|
1068
1353
|
authoringService: options && options.authoringService,
|
|
1354
|
+
liveAuthoringService,
|
|
1355
|
+
allowWrite: options && options.allowWrite,
|
|
1069
1356
|
allowAuthoring: options && options.allowAuthoring,
|
|
1070
1357
|
allowRuntimeRemoteLoad: options && options.allowRuntimeRemoteLoad,
|
|
1071
1358
|
allowComputationAuthoring: options && options.allowComputationAuthoring,
|
|
@@ -1106,6 +1393,9 @@ function registerMcpInterface(state) {
|
|
|
1106
1393
|
description: definition.description,
|
|
1107
1394
|
annotations: definition.annotations,
|
|
1108
1395
|
inputSchema: fromJsonSchema(definition.inputSchema),
|
|
1396
|
+
...(definition.outputSchema
|
|
1397
|
+
? { outputSchema: fromJsonSchema(definition.outputSchema) }
|
|
1398
|
+
: {}),
|
|
1109
1399
|
},
|
|
1110
1400
|
async (args) => {
|
|
1111
1401
|
const current = pendingToolCall.then(async () => {
|
package/src/store.js
CHANGED
|
@@ -169,6 +169,7 @@ class FileConceptStore {
|
|
|
169
169
|
throw new Error("Proposal root cannot be a symbolic link.");
|
|
170
170
|
}
|
|
171
171
|
this.proposalLocks = new Map();
|
|
172
|
+
this.writeQueue = Promise.resolve();
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
static fromProject(projectPath, options) {
|
|
@@ -357,6 +358,12 @@ class FileConceptStore {
|
|
|
357
358
|
}
|
|
358
359
|
}
|
|
359
360
|
|
|
361
|
+
async withWriteLock(operation) {
|
|
362
|
+
const current = this.writeQueue.then(operation, operation);
|
|
363
|
+
this.writeQueue = current.catch(() => {});
|
|
364
|
+
return current;
|
|
365
|
+
}
|
|
366
|
+
|
|
360
367
|
listProposalFiles() {
|
|
361
368
|
const root = this.proposalDirectory("", false);
|
|
362
369
|
if (!fs.existsSync(root)) {
|
|
@@ -454,7 +461,9 @@ class FileConceptStore {
|
|
|
454
461
|
}
|
|
455
462
|
|
|
456
463
|
async acceptProposal(id, authoringService, options) {
|
|
457
|
-
return this.
|
|
464
|
+
return this.withWriteLock(() => (
|
|
465
|
+
this.withProposalLock(id, (canonicalId) => this.acceptProposalUnlocked(canonicalId, authoringService, options))
|
|
466
|
+
));
|
|
458
467
|
}
|
|
459
468
|
|
|
460
469
|
async acceptProposalUnlocked(id, authoringService, options) {
|