@lucern/mcp 0.3.0-alpha.3 → 0.3.0-alpha.4
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/dist/cli.js +18970 -16917
- package/dist/cli.js.map +1 -1
- package/dist/gateway.d.ts +7 -1
- package/dist/gateway.js +1615 -87
- package/dist/gateway.js.map +1 -1
- package/dist/hosted-route.js +2631 -1050
- package/dist/hosted-route.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +19091 -17033
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +1416 -100
- package/dist/runtime.js.map +1 -1
- package/package.json +6 -6
package/dist/hosted-route.js
CHANGED
|
@@ -3,6 +3,8 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mc
|
|
|
3
3
|
import '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { v } from 'convex/values';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
6
8
|
|
|
7
9
|
// src/hosted-route.ts
|
|
8
10
|
|
|
@@ -234,14 +236,15 @@ function normalizeCanonicalLucernAuthContext(input) {
|
|
|
234
236
|
);
|
|
235
237
|
const roles = cleanStringList(input.roles);
|
|
236
238
|
const scopes = cleanStringList(input.scopes);
|
|
237
|
-
|
|
239
|
+
const principalType = requirePrincipalType(input.principalType);
|
|
240
|
+
const authMode = requireAuthMode(input.authMode);
|
|
241
|
+
const roleBasedInteractiveAuth = authMode === "interactive_user" && roles.length > 0;
|
|
242
|
+
if (roles.length === 0 || scopes.length === 0 && !roleBasedInteractiveAuth) {
|
|
238
243
|
throw new LucernSdkAuthContextError(
|
|
239
244
|
"membership_missing",
|
|
240
245
|
"Canonical Lucern SDK auth context requires non-empty roles and scopes."
|
|
241
246
|
);
|
|
242
247
|
}
|
|
243
|
-
const principalType = requirePrincipalType(input.principalType);
|
|
244
|
-
const authMode = requireAuthMode(input.authMode);
|
|
245
248
|
const subject = cleanString(input.permit?.subject) ?? principalId;
|
|
246
249
|
const tenant = cleanString(input.permit?.tenant) ?? tenantId;
|
|
247
250
|
const workspace = cleanString(input.permit?.workspace) ?? workspaceId;
|
|
@@ -1410,8 +1413,8 @@ function maybeThrowDeviceError(payload) {
|
|
|
1410
1413
|
function createAuthDeviceClient(config = {}) {
|
|
1411
1414
|
const fetchImpl = config.fetchImpl ?? fetch;
|
|
1412
1415
|
const baseUrl = authBaseUrl(config);
|
|
1413
|
-
async function post(
|
|
1414
|
-
return fetchImpl(`${baseUrl}${
|
|
1416
|
+
async function post(path2, body4) {
|
|
1417
|
+
return fetchImpl(`${baseUrl}${path2}`, {
|
|
1415
1418
|
method: "POST",
|
|
1416
1419
|
headers: { "content-type": "application/json" },
|
|
1417
1420
|
body: JSON.stringify(body4)
|
|
@@ -4348,7 +4351,9 @@ function createGraphAnalysisClient(config = {}) {
|
|
|
4348
4351
|
topicId: requireTopicId2(input),
|
|
4349
4352
|
workspaceId: input.workspaceId,
|
|
4350
4353
|
analysisId: input.analysisId,
|
|
4351
|
-
|
|
4354
|
+
minimumCreatedAt: input.minimumCreatedAt ?? input.since ?? input.createdAt ?? input.analysisCreatedAt,
|
|
4355
|
+
sourceNodeIds: input.sourceNodeIds?.join(",") ?? (input.nodeId ? input.nodeId : void 0),
|
|
4356
|
+
sourceEdgeIds: input.sourceEdgeIds?.join(",") ?? (input.edgeId ? input.edgeId : void 0),
|
|
4352
4357
|
limit: input.limit,
|
|
4353
4358
|
cursor: input.cursor
|
|
4354
4359
|
})}`
|
|
@@ -5113,6 +5118,7 @@ var CONTRACTS = {
|
|
|
5113
5118
|
"archive_belief": { method: "DELETE", path: "/beliefs", kind: "mutation", idempotent: true, surfaceIntent: "mcp_core" },
|
|
5114
5119
|
"archive_ontology": { method: "DELETE", path: "/ontologies", kind: "mutation", idempotent: true, surfaceIntent: "mcp_governance" },
|
|
5115
5120
|
"archive_question": { method: "DELETE", path: "/questions", kind: "mutation", idempotent: true, surfaceIntent: "mcp_core" },
|
|
5121
|
+
"begin_build_session": { method: "POST", path: "/mcp/build-session/begin", kind: "mutation", idempotent: true, surfaceIntent: "system" },
|
|
5116
5122
|
"bisect_confidence": { method: "POST", path: "/beliefs/confidence/bisect", kind: "query", idempotent: false, surfaceIntent: "mcp_core" },
|
|
5117
5123
|
"broadcast_message": { method: "POST", path: "/coordination/messages/broadcast", kind: "mutation", idempotent: true, surfaceIntent: "system" },
|
|
5118
5124
|
"check_permission": { method: "POST", path: "/identity/check-permission", kind: "query", idempotent: false, surfaceIntent: "mcp_core" },
|
|
@@ -5241,9 +5247,9 @@ function createFunctionSurfaceClient(config = {}) {
|
|
|
5241
5247
|
function execute(name, input, idempotencyKey) {
|
|
5242
5248
|
const contract = CONTRACTS[name];
|
|
5243
5249
|
const payload = withSdkSessionId(input, sessionId);
|
|
5244
|
-
const
|
|
5250
|
+
const path2 = contract.method === "GET" ? `${contract.path}${toFunctionSurfaceQuery(payload)}` : contract.path;
|
|
5245
5251
|
return gateway.request({
|
|
5246
|
-
path: `/api/platform/v1${
|
|
5252
|
+
path: `/api/platform/v1${path2}`,
|
|
5247
5253
|
method: contract.method,
|
|
5248
5254
|
body: contract.method === "GET" ? void 0 : payload,
|
|
5249
5255
|
idempotencyKey: contract.kind !== "query" && Boolean(contract.idempotent) ? idempotencyKey ?? randomIdempotencyKey() : void 0
|
|
@@ -5284,6 +5290,9 @@ function createFunctionSurfaceClient(config = {}) {
|
|
|
5284
5290
|
archiveQuestion(input = {}, idempotencyKey) {
|
|
5285
5291
|
return execute("archive_question", input, idempotencyKey);
|
|
5286
5292
|
},
|
|
5293
|
+
beginBuildSession(input = {}, idempotencyKey) {
|
|
5294
|
+
return execute("begin_build_session", input, idempotencyKey);
|
|
5295
|
+
},
|
|
5287
5296
|
bisectConfidence(input = {}, idempotencyKey) {
|
|
5288
5297
|
return execute("bisect_confidence", input, idempotencyKey);
|
|
5289
5298
|
},
|
|
@@ -7218,6 +7227,13 @@ function requireTopicId4(args) {
|
|
|
7218
7227
|
}
|
|
7219
7228
|
return topicId;
|
|
7220
7229
|
}
|
|
7230
|
+
function requireTopicOrProjectId(args) {
|
|
7231
|
+
const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
|
|
7232
|
+
if (!topicId) {
|
|
7233
|
+
throw new Error("topicId is required");
|
|
7234
|
+
}
|
|
7235
|
+
return topicId;
|
|
7236
|
+
}
|
|
7221
7237
|
var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
|
|
7222
7238
|
function matchesAuditNodeReference(value, nodeId) {
|
|
7223
7239
|
if (Array.isArray(value)) {
|
|
@@ -7253,6 +7269,23 @@ function requireBaseRate(args) {
|
|
|
7253
7269
|
function exposeGatewayData(response) {
|
|
7254
7270
|
return Object.assign({}, response, response.data);
|
|
7255
7271
|
}
|
|
7272
|
+
function sdkQueryString(input) {
|
|
7273
|
+
const params = new URLSearchParams();
|
|
7274
|
+
for (const [key, value] of Object.entries(input)) {
|
|
7275
|
+
if (value === void 0 || value === null) {
|
|
7276
|
+
continue;
|
|
7277
|
+
}
|
|
7278
|
+
if (Array.isArray(value)) {
|
|
7279
|
+
if (value.length > 0) {
|
|
7280
|
+
params.set(key, value.join(","));
|
|
7281
|
+
}
|
|
7282
|
+
continue;
|
|
7283
|
+
}
|
|
7284
|
+
params.set(key, String(value));
|
|
7285
|
+
}
|
|
7286
|
+
const serialized = params.toString();
|
|
7287
|
+
return serialized ? `?${serialized}` : "";
|
|
7288
|
+
}
|
|
7256
7289
|
function createLucernClient(config = {}) {
|
|
7257
7290
|
const gatewayConfig = toGatewayConfig(config);
|
|
7258
7291
|
const beliefsClient = createBeliefsClient(gatewayConfig);
|
|
@@ -7673,6 +7706,30 @@ function createLucernClient(config = {}) {
|
|
|
7673
7706
|
batchCreate(input, idempotencyKey) {
|
|
7674
7707
|
return graphClient.batchCreateNodes(input, idempotencyKey);
|
|
7675
7708
|
},
|
|
7709
|
+
listByTopicAndType(input) {
|
|
7710
|
+
return gateway.request({
|
|
7711
|
+
path: `/api/platform/v1/nodes${sdkQueryString({
|
|
7712
|
+
topicId: requireTopicOrProjectId(input),
|
|
7713
|
+
nodeType: input.nodeType,
|
|
7714
|
+
nodeTypes: input.nodeTypes,
|
|
7715
|
+
query: input.query,
|
|
7716
|
+
sourceText: input.sourceText,
|
|
7717
|
+
limit: input.limit,
|
|
7718
|
+
cursor: input.cursor
|
|
7719
|
+
})}`
|
|
7720
|
+
}).then(exposeGatewayData);
|
|
7721
|
+
},
|
|
7722
|
+
countByTopicAndType(input) {
|
|
7723
|
+
return gateway.request({
|
|
7724
|
+
path: `/api/platform/v1/nodes/count${sdkQueryString({
|
|
7725
|
+
topicId: requireTopicOrProjectId(input),
|
|
7726
|
+
nodeType: input.nodeType,
|
|
7727
|
+
nodeTypes: input.nodeTypes,
|
|
7728
|
+
query: input.query,
|
|
7729
|
+
limit: input.limit
|
|
7730
|
+
})}`
|
|
7731
|
+
}).then(exposeGatewayData);
|
|
7732
|
+
},
|
|
7676
7733
|
supersede(input, idempotencyKey) {
|
|
7677
7734
|
return graphClient.supersedeNode(input, idempotencyKey);
|
|
7678
7735
|
},
|
|
@@ -7683,6 +7740,78 @@ function createLucernClient(config = {}) {
|
|
|
7683
7740
|
return graphClient.hardDeleteNode(input, idempotencyKey);
|
|
7684
7741
|
}
|
|
7685
7742
|
};
|
|
7743
|
+
const publicationNamespace = {
|
|
7744
|
+
create(input, idempotencyKey) {
|
|
7745
|
+
return gateway.request({
|
|
7746
|
+
path: "/api/platform/v1/publication",
|
|
7747
|
+
method: "POST",
|
|
7748
|
+
body: input,
|
|
7749
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
7750
|
+
}).then(exposeGatewayData);
|
|
7751
|
+
},
|
|
7752
|
+
update(publicationId, input, idempotencyKey) {
|
|
7753
|
+
return gateway.request({
|
|
7754
|
+
path: `/api/platform/v1/publication/${encodeURIComponent(
|
|
7755
|
+
publicationId
|
|
7756
|
+
)}`,
|
|
7757
|
+
method: "PATCH",
|
|
7758
|
+
body: input,
|
|
7759
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
7760
|
+
}).then(exposeGatewayData);
|
|
7761
|
+
},
|
|
7762
|
+
list(input = {}) {
|
|
7763
|
+
return gateway.request({
|
|
7764
|
+
path: `/api/platform/v1/publication${sdkQueryString(input)}`
|
|
7765
|
+
}).then(exposeGatewayData);
|
|
7766
|
+
},
|
|
7767
|
+
getByTopic(input) {
|
|
7768
|
+
const topicId = typeof input === "string" ? input : input.topicId;
|
|
7769
|
+
const workspaceId = typeof input === "string" ? void 0 : input.workspaceId;
|
|
7770
|
+
return gateway.request({
|
|
7771
|
+
path: `/api/platform/v1/publication/by-topic/${encodeURIComponent(
|
|
7772
|
+
topicId
|
|
7773
|
+
)}${sdkQueryString({ workspaceId })}`
|
|
7774
|
+
}).then(exposeGatewayData);
|
|
7775
|
+
},
|
|
7776
|
+
publish(publicationId, input = {}, idempotencyKey) {
|
|
7777
|
+
return gateway.request({
|
|
7778
|
+
path: `/api/platform/v1/publication/${encodeURIComponent(
|
|
7779
|
+
publicationId
|
|
7780
|
+
)}/publish`,
|
|
7781
|
+
method: "POST",
|
|
7782
|
+
body: input,
|
|
7783
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
7784
|
+
}).then(exposeGatewayData);
|
|
7785
|
+
},
|
|
7786
|
+
unpublish(publicationId, input = {}, idempotencyKey) {
|
|
7787
|
+
return gateway.request({
|
|
7788
|
+
path: `/api/platform/v1/publication/${encodeURIComponent(
|
|
7789
|
+
publicationId
|
|
7790
|
+
)}/unpublish`,
|
|
7791
|
+
method: "POST",
|
|
7792
|
+
body: input,
|
|
7793
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
7794
|
+
}).then(exposeGatewayData);
|
|
7795
|
+
},
|
|
7796
|
+
remove(publicationId, input = {}) {
|
|
7797
|
+
return gateway.request({
|
|
7798
|
+
path: `/api/platform/v1/publication/${encodeURIComponent(
|
|
7799
|
+
publicationId
|
|
7800
|
+
)}${sdkQueryString(input)}`,
|
|
7801
|
+
method: "DELETE"
|
|
7802
|
+
}).then(exposeGatewayData);
|
|
7803
|
+
}
|
|
7804
|
+
};
|
|
7805
|
+
const ontologyLinksNamespace = {
|
|
7806
|
+
...ontologyLinksClient,
|
|
7807
|
+
resolveThemeSource(input) {
|
|
7808
|
+
return gateway.request({
|
|
7809
|
+
path: "/api/platform/v1/ontology-links/theme-source",
|
|
7810
|
+
method: "POST",
|
|
7811
|
+
body: input
|
|
7812
|
+
}).then(exposeGatewayData);
|
|
7813
|
+
}
|
|
7814
|
+
};
|
|
7686
7815
|
return {
|
|
7687
7816
|
config,
|
|
7688
7817
|
version: LUCERN_SDK_VERSION,
|
|
@@ -8164,6 +8293,54 @@ function createLucernClient(config = {}) {
|
|
|
8164
8293
|
}));
|
|
8165
8294
|
}
|
|
8166
8295
|
},
|
|
8296
|
+
themes: {
|
|
8297
|
+
listByTopic(input) {
|
|
8298
|
+
return gateway.request({
|
|
8299
|
+
path: `/api/platform/v1/themes${sdkQueryString({
|
|
8300
|
+
topicId: requireTopicOrProjectId(input),
|
|
8301
|
+
query: input.query,
|
|
8302
|
+
limit: input.limit,
|
|
8303
|
+
cursor: input.cursor
|
|
8304
|
+
})}`
|
|
8305
|
+
}).then(exposeGatewayData);
|
|
8306
|
+
}
|
|
8307
|
+
},
|
|
8308
|
+
graphSearch: {
|
|
8309
|
+
keywordSearchNodes(input) {
|
|
8310
|
+
return gateway.request({
|
|
8311
|
+
path: "/api/platform/v1/graph-search/keyword-nodes",
|
|
8312
|
+
method: "POST",
|
|
8313
|
+
body: {
|
|
8314
|
+
...input,
|
|
8315
|
+
topicId: requireTopicOrProjectId(input),
|
|
8316
|
+
projectId: void 0
|
|
8317
|
+
}
|
|
8318
|
+
}).then(exposeGatewayData);
|
|
8319
|
+
}
|
|
8320
|
+
},
|
|
8321
|
+
classifiers: {
|
|
8322
|
+
listBeliefCandidates(input) {
|
|
8323
|
+
return gateway.request({
|
|
8324
|
+
path: `/api/platform/v1/classifiers/belief-candidates${sdkQueryString({
|
|
8325
|
+
topicId: requireTopicOrProjectId(input),
|
|
8326
|
+
classifierKey: input.classifierKey,
|
|
8327
|
+
query: input.query,
|
|
8328
|
+
limit: input.limit,
|
|
8329
|
+
cursor: input.cursor
|
|
8330
|
+
})}`
|
|
8331
|
+
}).then(exposeGatewayData);
|
|
8332
|
+
}
|
|
8333
|
+
},
|
|
8334
|
+
archetypes: {
|
|
8335
|
+
getJudgmentSignature(input) {
|
|
8336
|
+
return gateway.request({
|
|
8337
|
+
path: `/api/platform/v1/archetypes/judgment-signature${sdkQueryString({
|
|
8338
|
+
topicId: requireTopicOrProjectId(input),
|
|
8339
|
+
principalId: input.principalId
|
|
8340
|
+
})}`
|
|
8341
|
+
}).then(exposeGatewayData);
|
|
8342
|
+
}
|
|
8343
|
+
},
|
|
8167
8344
|
judgments: {
|
|
8168
8345
|
create(input) {
|
|
8169
8346
|
return decisionsClient.createJudgment(input);
|
|
@@ -8205,6 +8382,52 @@ function createLucernClient(config = {}) {
|
|
|
8205
8382
|
});
|
|
8206
8383
|
}
|
|
8207
8384
|
},
|
|
8385
|
+
decisions: {
|
|
8386
|
+
create(input) {
|
|
8387
|
+
return decisionsClient.createJudgment(input);
|
|
8388
|
+
},
|
|
8389
|
+
record(input) {
|
|
8390
|
+
return decisionsClient.recordJudgment(input);
|
|
8391
|
+
},
|
|
8392
|
+
list(query5) {
|
|
8393
|
+
return decisionsClient.listJudgments(query5);
|
|
8394
|
+
},
|
|
8395
|
+
get(decisionId) {
|
|
8396
|
+
return decisionsClient.getJudgment(decisionId);
|
|
8397
|
+
},
|
|
8398
|
+
recordOutcome(decisionId, input) {
|
|
8399
|
+
return decisionsClient.recordJudgmentOutcome(decisionId, input);
|
|
8400
|
+
},
|
|
8401
|
+
lessons(decisionId, input, idempotencyKey) {
|
|
8402
|
+
return gateway.request({
|
|
8403
|
+
path: `/api/platform/v1/decisions/${encodeURIComponent(
|
|
8404
|
+
decisionId
|
|
8405
|
+
)}/lessons`,
|
|
8406
|
+
method: "POST",
|
|
8407
|
+
body: input,
|
|
8408
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
8409
|
+
}).then(exposeGatewayData);
|
|
8410
|
+
},
|
|
8411
|
+
archive(decisionId, input = {}, idempotencyKey) {
|
|
8412
|
+
return gateway.request({
|
|
8413
|
+
path: `/api/platform/v1/decisions/${encodeURIComponent(
|
|
8414
|
+
decisionId
|
|
8415
|
+
)}/archive`,
|
|
8416
|
+
method: "POST",
|
|
8417
|
+
body: input,
|
|
8418
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
8419
|
+
}).then(exposeGatewayData);
|
|
8420
|
+
},
|
|
8421
|
+
readiness(topicId) {
|
|
8422
|
+
return decisionsClient.getJudgmentReadiness({ topicId });
|
|
8423
|
+
},
|
|
8424
|
+
calibration(topicId) {
|
|
8425
|
+
return decisionsClient.getJudgmentCalibration({ topicId });
|
|
8426
|
+
},
|
|
8427
|
+
pendingOutcomeReview(topicId) {
|
|
8428
|
+
return decisionsClient.listPendingJudgmentOutcomeReview({ topicId });
|
|
8429
|
+
}
|
|
8430
|
+
},
|
|
8208
8431
|
worktrees: {
|
|
8209
8432
|
createBranch(input) {
|
|
8210
8433
|
return workflowClient.createBranch(input);
|
|
@@ -8227,7 +8450,21 @@ function createLucernClient(config = {}) {
|
|
|
8227
8450
|
topicId: requireTopicId4(input),
|
|
8228
8451
|
objective: input.objective,
|
|
8229
8452
|
hypothesis: input.hypothesis,
|
|
8453
|
+
rationale: input.rationale,
|
|
8454
|
+
worktreeType: input.worktreeType,
|
|
8455
|
+
startDate: input.startDate,
|
|
8456
|
+
endDate: input.endDate,
|
|
8457
|
+
durationWeeks: input.durationWeeks,
|
|
8458
|
+
confidenceImpact: input.confidenceImpact,
|
|
8459
|
+
beliefFocus: input.beliefFocus,
|
|
8230
8460
|
beliefIds: input.beliefIds,
|
|
8461
|
+
targetBeliefIds: input.targetBeliefIds,
|
|
8462
|
+
targetQuestionIds: input.targetQuestionIds,
|
|
8463
|
+
keyQuestions: input.keyQuestions,
|
|
8464
|
+
evidenceSignals: input.evidenceSignals,
|
|
8465
|
+
decisionGate: input.decisionGate,
|
|
8466
|
+
goCriteria: input.goCriteria,
|
|
8467
|
+
noGoSignals: input.noGoSignals,
|
|
8231
8468
|
autoShape: input.autoShape,
|
|
8232
8469
|
domainPackId: input.domainPackId,
|
|
8233
8470
|
campaign: input.campaign,
|
|
@@ -8240,7 +8477,8 @@ function createLucernClient(config = {}) {
|
|
|
8240
8477
|
proofArtifacts: input.proofArtifacts,
|
|
8241
8478
|
staffingHint: typeof input.staffingHint === "string" ? input.staffingHint : void 0,
|
|
8242
8479
|
lastReconciledAt: input.lastReconciledAt,
|
|
8243
|
-
autoFixPolicy: input.autoFixPolicy
|
|
8480
|
+
autoFixPolicy: input.autoFixPolicy,
|
|
8481
|
+
lensId: input.lensId
|
|
8244
8482
|
});
|
|
8245
8483
|
},
|
|
8246
8484
|
add(input) {
|
|
@@ -8249,7 +8487,21 @@ function createLucernClient(config = {}) {
|
|
|
8249
8487
|
topicId: requireTopicId4(input),
|
|
8250
8488
|
objective: input.objective,
|
|
8251
8489
|
hypothesis: input.hypothesis,
|
|
8490
|
+
rationale: input.rationale,
|
|
8491
|
+
worktreeType: input.worktreeType,
|
|
8492
|
+
startDate: input.startDate,
|
|
8493
|
+
endDate: input.endDate,
|
|
8494
|
+
durationWeeks: input.durationWeeks,
|
|
8495
|
+
confidenceImpact: input.confidenceImpact,
|
|
8496
|
+
beliefFocus: input.beliefFocus,
|
|
8252
8497
|
beliefIds: input.beliefIds,
|
|
8498
|
+
targetBeliefIds: input.targetBeliefIds,
|
|
8499
|
+
targetQuestionIds: input.targetQuestionIds,
|
|
8500
|
+
keyQuestions: input.keyQuestions,
|
|
8501
|
+
evidenceSignals: input.evidenceSignals,
|
|
8502
|
+
decisionGate: input.decisionGate,
|
|
8503
|
+
goCriteria: input.goCriteria,
|
|
8504
|
+
noGoSignals: input.noGoSignals,
|
|
8253
8505
|
autoShape: input.autoShape,
|
|
8254
8506
|
domainPackId: input.domainPackId,
|
|
8255
8507
|
campaign: input.campaign,
|
|
@@ -8262,7 +8514,8 @@ function createLucernClient(config = {}) {
|
|
|
8262
8514
|
proofArtifacts: input.proofArtifacts,
|
|
8263
8515
|
staffingHint: typeof input.staffingHint === "string" ? input.staffingHint : void 0,
|
|
8264
8516
|
lastReconciledAt: input.lastReconciledAt,
|
|
8265
|
-
autoFixPolicy: input.autoFixPolicy
|
|
8517
|
+
autoFixPolicy: input.autoFixPolicy,
|
|
8518
|
+
lensId: input.lensId
|
|
8266
8519
|
});
|
|
8267
8520
|
},
|
|
8268
8521
|
list(query5) {
|
|
@@ -8272,6 +8525,22 @@ function createLucernClient(config = {}) {
|
|
|
8272
8525
|
limit: query5.limit
|
|
8273
8526
|
});
|
|
8274
8527
|
},
|
|
8528
|
+
listByTopic(query5) {
|
|
8529
|
+
return worktreesFacade.list({
|
|
8530
|
+
topicId: requireTopicId4(query5),
|
|
8531
|
+
status: query5.status,
|
|
8532
|
+
limit: query5.limit
|
|
8533
|
+
});
|
|
8534
|
+
},
|
|
8535
|
+
findByPairedSprint(input) {
|
|
8536
|
+
return gateway.request({
|
|
8537
|
+
path: `/api/platform/v1/worktrees/paired-sprint${sdkQueryString({
|
|
8538
|
+
sprintId: input.sprintId,
|
|
8539
|
+
topicId: input.topicId ?? input.projectId,
|
|
8540
|
+
limit: input.limit
|
|
8541
|
+
})}`
|
|
8542
|
+
}).then(exposeGatewayData);
|
|
8543
|
+
},
|
|
8275
8544
|
activate(worktreeId) {
|
|
8276
8545
|
return worktreesFacade.activate({ id: worktreeId });
|
|
8277
8546
|
},
|
|
@@ -8423,6 +8692,31 @@ function createLucernClient(config = {}) {
|
|
|
8423
8692
|
status: typeof input.status === "string" ? input.status : void 0,
|
|
8424
8693
|
limit: typeof input.limit === "number" ? input.limit : void 0
|
|
8425
8694
|
});
|
|
8695
|
+
},
|
|
8696
|
+
listByTopic(input) {
|
|
8697
|
+
return tasksFacade.list({
|
|
8698
|
+
topicId: requireTopicId4(input),
|
|
8699
|
+
status: typeof input.status === "string" ? input.status : void 0,
|
|
8700
|
+
limit: typeof input.limit === "number" ? input.limit : void 0
|
|
8701
|
+
});
|
|
8702
|
+
},
|
|
8703
|
+
listByWorktree(input) {
|
|
8704
|
+
return tasksFacade.list({
|
|
8705
|
+
topicId: typeof input.topicId === "string" ? input.topicId : void 0,
|
|
8706
|
+
worktreeId: input.worktreeId,
|
|
8707
|
+
status: typeof input.status === "string" ? input.status : void 0,
|
|
8708
|
+
limit: typeof input.limit === "number" ? input.limit : void 0
|
|
8709
|
+
});
|
|
8710
|
+
},
|
|
8711
|
+
linkChat(taskId, input, idempotencyKey) {
|
|
8712
|
+
return gateway.request({
|
|
8713
|
+
path: `/api/platform/v1/tasks/${encodeURIComponent(
|
|
8714
|
+
taskId
|
|
8715
|
+
)}/link-chat`,
|
|
8716
|
+
method: "POST",
|
|
8717
|
+
body: input,
|
|
8718
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
8719
|
+
}).then(exposeGatewayData);
|
|
8426
8720
|
}
|
|
8427
8721
|
},
|
|
8428
8722
|
topics: {
|
|
@@ -8707,11 +9001,13 @@ function createLucernClient(config = {}) {
|
|
|
8707
9001
|
graphAnalysis: graphAnalysisClient,
|
|
8708
9002
|
graphRecommendations: graphRecommendationsClient,
|
|
8709
9003
|
orgGraphSearch: orgGraphSearchClient,
|
|
8710
|
-
ontologyLinks:
|
|
9004
|
+
ontologyLinks: ontologyLinksNamespace,
|
|
8711
9005
|
graphStateClassifier: graphStateClassifierClient,
|
|
8712
9006
|
modelRuntime: modelRuntimeClient,
|
|
8713
9007
|
jobs: jobsClient,
|
|
8714
9008
|
telemetry: telemetryClient,
|
|
9009
|
+
publication: publicationNamespace,
|
|
9010
|
+
contentPublication: publicationNamespace,
|
|
8715
9011
|
tools: {
|
|
8716
9012
|
listCatalog: toolRegistryClient.listCatalog,
|
|
8717
9013
|
listExecutable: toolRegistryClient.listExecutable,
|
|
@@ -9438,6 +9734,14 @@ var ADD_WORKTREE = {
|
|
|
9438
9734
|
description: "Check out a branch into an active worktree for investigation. Like `git worktree add <branch>` \u2014 creates independent working state on a thematic branch. Beliefs committed within the worktree can be freely amended (draft code on a feature branch). When investigation is complete, `merge` integrates findings into main.",
|
|
9439
9735
|
parameters: {
|
|
9440
9736
|
title: { type: "string", description: "Worktree name/objective" },
|
|
9737
|
+
name: {
|
|
9738
|
+
type: "string",
|
|
9739
|
+
description: "Optional storage-name alias for callers that already use backend naming"
|
|
9740
|
+
},
|
|
9741
|
+
projectId: {
|
|
9742
|
+
type: "string",
|
|
9743
|
+
description: "Legacy topicId alias"
|
|
9744
|
+
},
|
|
9441
9745
|
topicId: { type: "string", description: "Optional topic scope hint" },
|
|
9442
9746
|
branchId: {
|
|
9443
9747
|
type: "string",
|
|
@@ -9451,14 +9755,87 @@ var ADD_WORKTREE = {
|
|
|
9451
9755
|
type: "string",
|
|
9452
9756
|
description: "The testable claim this worktree investigates"
|
|
9453
9757
|
},
|
|
9758
|
+
rationale: {
|
|
9759
|
+
type: "string",
|
|
9760
|
+
description: "Why this worktree exists and why it belongs in the campaign"
|
|
9761
|
+
},
|
|
9762
|
+
worktreeType: {
|
|
9763
|
+
type: "string",
|
|
9764
|
+
description: "Schema-enum worktree type used by the kernel lifecycle and retrieval layers"
|
|
9765
|
+
},
|
|
9766
|
+
gate: {
|
|
9767
|
+
type: "string",
|
|
9768
|
+
description: "Exit gate name for this worktree"
|
|
9769
|
+
},
|
|
9770
|
+
startDate: {
|
|
9771
|
+
type: "number",
|
|
9772
|
+
description: "Planned start timestamp in milliseconds since epoch"
|
|
9773
|
+
},
|
|
9774
|
+
endDate: {
|
|
9775
|
+
type: "number",
|
|
9776
|
+
description: "Planned end timestamp in milliseconds since epoch"
|
|
9777
|
+
},
|
|
9778
|
+
durationWeeks: {
|
|
9779
|
+
type: "number",
|
|
9780
|
+
description: "Planned duration in weeks"
|
|
9781
|
+
},
|
|
9782
|
+
confidenceImpact: {
|
|
9783
|
+
type: "string",
|
|
9784
|
+
description: "Expected confidence impact if the worktree succeeds",
|
|
9785
|
+
enum: ["high", "medium", "low"]
|
|
9786
|
+
},
|
|
9787
|
+
beliefFocus: {
|
|
9788
|
+
type: "string",
|
|
9789
|
+
description: "Natural-language focus spanning the target belief neighborhood"
|
|
9790
|
+
},
|
|
9454
9791
|
beliefIds: {
|
|
9455
9792
|
type: "array",
|
|
9456
|
-
description: "
|
|
9793
|
+
description: "Legacy alias for targetBeliefIds"
|
|
9794
|
+
},
|
|
9795
|
+
beliefs: {
|
|
9796
|
+
type: "array",
|
|
9797
|
+
description: "Legacy alias for targetBeliefIds"
|
|
9798
|
+
},
|
|
9799
|
+
targetBeliefIds: {
|
|
9800
|
+
type: "array",
|
|
9801
|
+
description: "Belief node IDs this worktree is expected to test or update"
|
|
9802
|
+
},
|
|
9803
|
+
targetQuestionIds: {
|
|
9804
|
+
type: "array",
|
|
9805
|
+
description: "Question node IDs this worktree is expected to answer"
|
|
9806
|
+
},
|
|
9807
|
+
keyQuestions: {
|
|
9808
|
+
type: "array",
|
|
9809
|
+
description: "Inline key question objects with question, optional status, answer, answerConfidence, and linkedQuestionId"
|
|
9810
|
+
},
|
|
9811
|
+
evidenceSignals: {
|
|
9812
|
+
type: "array",
|
|
9813
|
+
description: "Evidence signal objects with signal, optional collected state, progress, and notes"
|
|
9814
|
+
},
|
|
9815
|
+
decisionGate: {
|
|
9816
|
+
type: "object",
|
|
9817
|
+
description: "Decision gate object with goCriteria, noGoSignals, optional verdict, rationale, decidedAt, and decidedBy"
|
|
9818
|
+
},
|
|
9819
|
+
goCriteria: {
|
|
9820
|
+
type: "array",
|
|
9821
|
+
description: "Shorthand go criteria used to build decisionGate"
|
|
9822
|
+
},
|
|
9823
|
+
noGoSignals: {
|
|
9824
|
+
type: "array",
|
|
9825
|
+
description: "Shorthand no-go signals used to build decisionGate"
|
|
9826
|
+
},
|
|
9827
|
+
proofArtifacts: {
|
|
9828
|
+
type: "array",
|
|
9829
|
+
description: "Expected proof artifacts required to close the worktree"
|
|
9457
9830
|
},
|
|
9458
9831
|
autoShape: {
|
|
9459
9832
|
type: "boolean",
|
|
9460
9833
|
description: "Whether to invoke inquiry auto-shaping during worktree creation"
|
|
9461
9834
|
},
|
|
9835
|
+
autoFixPolicy: {
|
|
9836
|
+
type: "object",
|
|
9837
|
+
description: "Policy for permitted automatic remediation inside the worktree"
|
|
9838
|
+
},
|
|
9462
9839
|
domainPackId: {
|
|
9463
9840
|
type: "string",
|
|
9464
9841
|
description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
|
|
@@ -9487,9 +9864,17 @@ var ADD_WORKTREE = {
|
|
|
9487
9864
|
type: "array",
|
|
9488
9865
|
description: "Worktree IDs blocked by this worktree"
|
|
9489
9866
|
},
|
|
9490
|
-
|
|
9867
|
+
staffingHint: {
|
|
9491
9868
|
type: "string",
|
|
9492
|
-
description: "
|
|
9869
|
+
description: "Suggested staffing or agent allocation note"
|
|
9870
|
+
},
|
|
9871
|
+
lensId: {
|
|
9872
|
+
type: "string",
|
|
9873
|
+
description: "Lens that scopes this worktree when applicable"
|
|
9874
|
+
},
|
|
9875
|
+
lastReconciledAt: {
|
|
9876
|
+
type: "number",
|
|
9877
|
+
description: "Timestamp when worktree metadata was last reconciled"
|
|
9493
9878
|
}
|
|
9494
9879
|
},
|
|
9495
9880
|
required: ["title", "topicId"],
|
|
@@ -9519,7 +9904,7 @@ var MERGE = {
|
|
|
9519
9904
|
worktreeId: { type: "string", description: "The worktree to merge" },
|
|
9520
9905
|
outcomes: {
|
|
9521
9906
|
type: "array",
|
|
9522
|
-
description: "
|
|
9907
|
+
description: "Merge outcomes as key-finding strings, or scoring outcomes for beliefs: { beliefId, confidence, rationale }"
|
|
9523
9908
|
},
|
|
9524
9909
|
summary: { type: "string", description: "Overall findings summary" }
|
|
9525
9910
|
},
|
|
@@ -12538,6 +12923,69 @@ var GENERATE_SESSION_HANDOFF = {
|
|
|
12538
12923
|
tier: "showcase",
|
|
12539
12924
|
internal: true
|
|
12540
12925
|
};
|
|
12926
|
+
var BEGIN_BUILD_SESSION = {
|
|
12927
|
+
name: "begin_build_session",
|
|
12928
|
+
description: "Bootstrap a coding build session for a Lucern worktree. Like `git worktree add` plus `git status` \u2014 returns the compact context packet an agent needs before editing.",
|
|
12929
|
+
parameters: {
|
|
12930
|
+
worktreeId: {
|
|
12931
|
+
type: "string",
|
|
12932
|
+
description: "The Lucern worktree ID to bootstrap."
|
|
12933
|
+
},
|
|
12934
|
+
branch: {
|
|
12935
|
+
type: "string",
|
|
12936
|
+
description: "Optional git branch name. Auto-generated from the worktree name when omitted."
|
|
12937
|
+
},
|
|
12938
|
+
branchBase: {
|
|
12939
|
+
type: "string",
|
|
12940
|
+
description: 'Base branch for the feature branch. Default: "staging".'
|
|
12941
|
+
},
|
|
12942
|
+
prBase: {
|
|
12943
|
+
type: "string",
|
|
12944
|
+
description: 'Target branch for the PR. Default: "staging".'
|
|
12945
|
+
},
|
|
12946
|
+
sessionMode: {
|
|
12947
|
+
type: "string",
|
|
12948
|
+
description: 'Session mode: "async" for Codex/headless or "interactive" for live sessions.',
|
|
12949
|
+
enum: ["async", "interactive"]
|
|
12950
|
+
},
|
|
12951
|
+
activateIfPlanning: {
|
|
12952
|
+
type: "boolean",
|
|
12953
|
+
description: "When true, automatically activate a planning worktree during bootstrap."
|
|
12954
|
+
}
|
|
12955
|
+
},
|
|
12956
|
+
required: ["worktreeId"],
|
|
12957
|
+
response: {
|
|
12958
|
+
description: "A compact build-session packet with worktree metadata, graph anchors, questions, dependencies, and git defaults.",
|
|
12959
|
+
fields: {
|
|
12960
|
+
topicId: "string \u2014 canonical topic scope",
|
|
12961
|
+
topicName: "string \u2014 human-readable topic name",
|
|
12962
|
+
worktreeId: "string \u2014 worktree ID",
|
|
12963
|
+
worktreeName: "string \u2014 human-readable worktree name",
|
|
12964
|
+
branch: "string \u2014 git branch name",
|
|
12965
|
+
branchBase: "string \u2014 base branch",
|
|
12966
|
+
prBase: "string \u2014 PR target branch",
|
|
12967
|
+
campaign: "number | null \u2014 top-level pipeline campaign",
|
|
12968
|
+
lane: "string \u2014 campaign lane",
|
|
12969
|
+
gate: "string \u2014 exit gate",
|
|
12970
|
+
hypothesis: "string \u2014 worktree hypothesis",
|
|
12971
|
+
focus: "string \u2014 session focus",
|
|
12972
|
+
status: "string \u2014 worktree status after optional activation",
|
|
12973
|
+
sessionMode: "string \u2014 async | interactive",
|
|
12974
|
+
targetBeliefIds: "array \u2014 scoped belief IDs",
|
|
12975
|
+
targetQuestionIds: "array \u2014 scoped question IDs",
|
|
12976
|
+
topBeliefs: "array \u2014 highest-confidence scoped beliefs",
|
|
12977
|
+
openQuestions: "array \u2014 open scoped questions",
|
|
12978
|
+
resolvedDecisions: "array \u2014 answered questions summarized for the session",
|
|
12979
|
+
dependencies: "array \u2014 upstream worktrees",
|
|
12980
|
+
unblocks: "array \u2014 downstream worktrees",
|
|
12981
|
+
mergeOrderNotes: "string \u2014 merge ordering advisory"
|
|
12982
|
+
}
|
|
12983
|
+
},
|
|
12984
|
+
ownerModule: "bootstrap",
|
|
12985
|
+
ontologyPrimitive: "worktree",
|
|
12986
|
+
tier: "showcase",
|
|
12987
|
+
internal: true
|
|
12988
|
+
};
|
|
12541
12989
|
var MCP_TOOL_CONTRACTS = {
|
|
12542
12990
|
// Belief lifecycle (commit, amend, fork, archive)
|
|
12543
12991
|
create_belief: CREATE_BELIEF,
|
|
@@ -12631,6 +13079,7 @@ var MCP_TOOL_CONTRACTS = {
|
|
|
12631
13079
|
get_agent_inbox: GET_AGENT_INBOX,
|
|
12632
13080
|
claim_files: CLAIM_FILES,
|
|
12633
13081
|
generate_session_handoff: GENERATE_SESSION_HANDOFF,
|
|
13082
|
+
begin_build_session: BEGIN_BUILD_SESSION,
|
|
12634
13083
|
// Policy / ACL (workhorse)
|
|
12635
13084
|
check_permission: CHECK_PERMISSION,
|
|
12636
13085
|
filter_by_permission: FILTER_BY_PERMISSION,
|
|
@@ -12844,6 +13293,7 @@ var PLATFORM_INTERNAL_OPERATION_NAMES = [
|
|
|
12844
13293
|
"get_change_history",
|
|
12845
13294
|
"get_failure_log",
|
|
12846
13295
|
"record_attempt",
|
|
13296
|
+
"begin_build_session",
|
|
12847
13297
|
"push",
|
|
12848
13298
|
"open_pull_request",
|
|
12849
13299
|
"record_judgment",
|
|
@@ -12898,7 +13348,6 @@ var SDK_ONLY_OPERATION_NAMES = [
|
|
|
12898
13348
|
"find_semantic_orphans"
|
|
12899
13349
|
];
|
|
12900
13350
|
var MCP_ONLY_INTERNAL_OPERATION_NAMES = [
|
|
12901
|
-
"begin_build_session",
|
|
12902
13351
|
"evaluate_engineering_contract",
|
|
12903
13352
|
"evaluate_research_contract"
|
|
12904
13353
|
];
|
|
@@ -12997,629 +13446,6 @@ var LUCERN_OPERATION_MANIFEST = {
|
|
|
12997
13446
|
};
|
|
12998
13447
|
globalThis.process?.env;
|
|
12999
13448
|
|
|
13000
|
-
// src/execution.ts
|
|
13001
|
-
var SCOPE_ALIAS_GROUPS = [];
|
|
13002
|
-
function createToolExecutionEnvelope(args) {
|
|
13003
|
-
return {
|
|
13004
|
-
toolName: args.toolName,
|
|
13005
|
-
params: args.params,
|
|
13006
|
-
contract: args.contract,
|
|
13007
|
-
transport: {
|
|
13008
|
-
kind: args.transportKind,
|
|
13009
|
-
surface: args.transportKind === "chat" ? "chat" : "mcp",
|
|
13010
|
-
normalizedAt: "handler_boundary"
|
|
13011
|
-
},
|
|
13012
|
-
auth: {
|
|
13013
|
-
mode: args.authMode
|
|
13014
|
-
},
|
|
13015
|
-
policy: {
|
|
13016
|
-
requiredScopes: args.requiredScopes,
|
|
13017
|
-
enforcement: "gateway"
|
|
13018
|
-
},
|
|
13019
|
-
audit: {
|
|
13020
|
-
source: "gateway_envelope",
|
|
13021
|
-
structuralFields: [
|
|
13022
|
-
"toolName",
|
|
13023
|
-
"code",
|
|
13024
|
-
"status",
|
|
13025
|
-
"correlationId",
|
|
13026
|
-
"policyTraceId",
|
|
13027
|
-
"invariant"
|
|
13028
|
-
]
|
|
13029
|
-
}
|
|
13030
|
-
};
|
|
13031
|
-
}
|
|
13032
|
-
function hasValue(value) {
|
|
13033
|
-
if (value === void 0 || value === null) {
|
|
13034
|
-
return false;
|
|
13035
|
-
}
|
|
13036
|
-
if (typeof value === "string") {
|
|
13037
|
-
return value.trim().length > 0;
|
|
13038
|
-
}
|
|
13039
|
-
if (Array.isArray(value)) {
|
|
13040
|
-
return value.length > 0;
|
|
13041
|
-
}
|
|
13042
|
-
return true;
|
|
13043
|
-
}
|
|
13044
|
-
function normalizeToolExecutionParams(params) {
|
|
13045
|
-
const normalized = { ...params };
|
|
13046
|
-
for (const aliases of SCOPE_ALIAS_GROUPS) {
|
|
13047
|
-
const sourceKey = aliases.find((key) => hasValue(normalized[key]));
|
|
13048
|
-
if (!sourceKey) {
|
|
13049
|
-
continue;
|
|
13050
|
-
}
|
|
13051
|
-
for (const key of aliases) {
|
|
13052
|
-
if (!hasValue(normalized[key])) {
|
|
13053
|
-
normalized[key] = normalized[sourceKey];
|
|
13054
|
-
}
|
|
13055
|
-
}
|
|
13056
|
-
}
|
|
13057
|
-
return normalized;
|
|
13058
|
-
}
|
|
13059
|
-
function parseToolExecutionMetadata(result) {
|
|
13060
|
-
const raw = result.content[0]?.text;
|
|
13061
|
-
if (!raw) {
|
|
13062
|
-
return { isError: Boolean(result.isError) };
|
|
13063
|
-
}
|
|
13064
|
-
try {
|
|
13065
|
-
const payload = JSON.parse(raw);
|
|
13066
|
-
return {
|
|
13067
|
-
isError: Boolean(result.isError),
|
|
13068
|
-
code: typeof payload.code === "string" ? payload.code : void 0,
|
|
13069
|
-
status: typeof payload.status === "number" ? payload.status : void 0,
|
|
13070
|
-
correlationId: typeof payload.correlationId === "string" || payload.correlationId === null ? payload.correlationId : void 0,
|
|
13071
|
-
policyTraceId: typeof payload.policyTraceId === "string" || payload.policyTraceId === null ? payload.policyTraceId : void 0,
|
|
13072
|
-
invariant: typeof payload.invariant === "string" || payload.invariant === null ? payload.invariant : void 0
|
|
13073
|
-
};
|
|
13074
|
-
} catch {
|
|
13075
|
-
return { isError: Boolean(result.isError) };
|
|
13076
|
-
}
|
|
13077
|
-
}
|
|
13078
|
-
async function executeToolWithEnvelope(args) {
|
|
13079
|
-
await args.hooks?.onEnvelope?.(args.envelope);
|
|
13080
|
-
const result = await args.execute();
|
|
13081
|
-
const metadata = parseToolExecutionMetadata(result);
|
|
13082
|
-
await args.hooks?.onAuditEvent?.({
|
|
13083
|
-
toolName: args.envelope.toolName,
|
|
13084
|
-
contractName: args.envelope.contract.name,
|
|
13085
|
-
transportKind: args.envelope.transport.kind,
|
|
13086
|
-
authMode: args.envelope.auth.mode,
|
|
13087
|
-
requiredScopes: args.envelope.policy.requiredScopes,
|
|
13088
|
-
source: args.envelope.audit.source,
|
|
13089
|
-
...metadata
|
|
13090
|
-
});
|
|
13091
|
-
return result;
|
|
13092
|
-
}
|
|
13093
|
-
|
|
13094
|
-
// src/types.ts
|
|
13095
|
-
var McpHandlerError = class extends Error {
|
|
13096
|
-
code;
|
|
13097
|
-
status;
|
|
13098
|
-
suggestion;
|
|
13099
|
-
constructor(message, code = "INVALID_REQUEST", status = 400, suggestion) {
|
|
13100
|
-
super(message);
|
|
13101
|
-
this.name = "McpHandlerError";
|
|
13102
|
-
this.code = code;
|
|
13103
|
-
this.status = status;
|
|
13104
|
-
this.suggestion = suggestion;
|
|
13105
|
-
}
|
|
13106
|
-
};
|
|
13107
|
-
|
|
13108
|
-
// src/handler-factory.ts
|
|
13109
|
-
function isMissing(value) {
|
|
13110
|
-
if (value === void 0 || value === null) {
|
|
13111
|
-
return true;
|
|
13112
|
-
}
|
|
13113
|
-
if (typeof value === "string") {
|
|
13114
|
-
return value.trim().length === 0;
|
|
13115
|
-
}
|
|
13116
|
-
if (Array.isArray(value)) {
|
|
13117
|
-
return value.length === 0;
|
|
13118
|
-
}
|
|
13119
|
-
return false;
|
|
13120
|
-
}
|
|
13121
|
-
function readString3(params, key, options = {}) {
|
|
13122
|
-
const value = params[key];
|
|
13123
|
-
if (value === void 0 || value === null) {
|
|
13124
|
-
if (options.required) {
|
|
13125
|
-
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
13126
|
-
}
|
|
13127
|
-
return;
|
|
13128
|
-
}
|
|
13129
|
-
if (typeof value !== "string") {
|
|
13130
|
-
throw new McpHandlerError(`Expected string parameter: ${key}`);
|
|
13131
|
-
}
|
|
13132
|
-
const trimmed = value.trim();
|
|
13133
|
-
if (!trimmed && options.required) {
|
|
13134
|
-
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
13135
|
-
}
|
|
13136
|
-
return trimmed || void 0;
|
|
13137
|
-
}
|
|
13138
|
-
function readNumber2(params, key, options = {}) {
|
|
13139
|
-
const value = params[key];
|
|
13140
|
-
if (value === void 0 || value === null) {
|
|
13141
|
-
if (options.required) {
|
|
13142
|
-
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
13143
|
-
}
|
|
13144
|
-
return;
|
|
13145
|
-
}
|
|
13146
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
13147
|
-
throw new McpHandlerError(`Expected numeric parameter: ${key}`);
|
|
13148
|
-
}
|
|
13149
|
-
return value;
|
|
13150
|
-
}
|
|
13151
|
-
function readBoolean(params, key, options = {}) {
|
|
13152
|
-
const value = params[key];
|
|
13153
|
-
if (value === void 0 || value === null) {
|
|
13154
|
-
if (options.required) {
|
|
13155
|
-
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
13156
|
-
}
|
|
13157
|
-
return;
|
|
13158
|
-
}
|
|
13159
|
-
if (typeof value !== "boolean") {
|
|
13160
|
-
throw new McpHandlerError(`Expected boolean parameter: ${key}`);
|
|
13161
|
-
}
|
|
13162
|
-
return value;
|
|
13163
|
-
}
|
|
13164
|
-
function readStringArray(params, key) {
|
|
13165
|
-
const value = params[key];
|
|
13166
|
-
if (value === void 0 || value === null) {
|
|
13167
|
-
return;
|
|
13168
|
-
}
|
|
13169
|
-
if (!Array.isArray(value)) {
|
|
13170
|
-
throw new McpHandlerError(`Expected array parameter: ${key}`);
|
|
13171
|
-
}
|
|
13172
|
-
const values = value.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
|
|
13173
|
-
return values.length > 0 ? values : void 0;
|
|
13174
|
-
}
|
|
13175
|
-
function readTopicId4(params, options = {}) {
|
|
13176
|
-
const value = params.topicId;
|
|
13177
|
-
if (value === void 0 || value === null) {
|
|
13178
|
-
if (options.required) {
|
|
13179
|
-
throw new McpHandlerError("Missing required parameter: topicId");
|
|
13180
|
-
}
|
|
13181
|
-
return;
|
|
13182
|
-
}
|
|
13183
|
-
if (typeof value !== "string") {
|
|
13184
|
-
throw new McpHandlerError("Expected string parameter: topicId");
|
|
13185
|
-
}
|
|
13186
|
-
const trimmed = value.trim();
|
|
13187
|
-
if (!trimmed && options.required) {
|
|
13188
|
-
throw new McpHandlerError("Missing required parameter: topicId");
|
|
13189
|
-
}
|
|
13190
|
-
return trimmed || void 0;
|
|
13191
|
-
}
|
|
13192
|
-
function toMcpResult(payload) {
|
|
13193
|
-
return {
|
|
13194
|
-
content: [{ type: "text", text: JSON.stringify(payload) }]
|
|
13195
|
-
};
|
|
13196
|
-
}
|
|
13197
|
-
function toMcpError(error) {
|
|
13198
|
-
if (error instanceof McpHandlerError) {
|
|
13199
|
-
return {
|
|
13200
|
-
isError: true,
|
|
13201
|
-
content: [
|
|
13202
|
-
{
|
|
13203
|
-
type: "text",
|
|
13204
|
-
text: JSON.stringify({
|
|
13205
|
-
code: error.code,
|
|
13206
|
-
status: error.status,
|
|
13207
|
-
message: error.message,
|
|
13208
|
-
suggestion: error.suggestion ?? null
|
|
13209
|
-
})
|
|
13210
|
-
}
|
|
13211
|
-
]
|
|
13212
|
-
};
|
|
13213
|
-
}
|
|
13214
|
-
if (error instanceof LucernApiError) {
|
|
13215
|
-
return {
|
|
13216
|
-
isError: true,
|
|
13217
|
-
content: [
|
|
13218
|
-
{
|
|
13219
|
-
type: "text",
|
|
13220
|
-
text: JSON.stringify({
|
|
13221
|
-
code: error.code,
|
|
13222
|
-
status: error.status,
|
|
13223
|
-
message: error.message,
|
|
13224
|
-
invariant: error.invariant ?? null,
|
|
13225
|
-
suggestion: error.suggestion ?? null,
|
|
13226
|
-
correlationId: error.correlationId,
|
|
13227
|
-
policyTraceId: error.policyTraceId
|
|
13228
|
-
})
|
|
13229
|
-
}
|
|
13230
|
-
]
|
|
13231
|
-
};
|
|
13232
|
-
}
|
|
13233
|
-
const message = error instanceof Error ? error.message : "Tool execution failed.";
|
|
13234
|
-
return {
|
|
13235
|
-
isError: true,
|
|
13236
|
-
content: [
|
|
13237
|
-
{
|
|
13238
|
-
type: "text",
|
|
13239
|
-
text: JSON.stringify({
|
|
13240
|
-
code: "INTERNAL_ERROR",
|
|
13241
|
-
status: 500,
|
|
13242
|
-
message
|
|
13243
|
-
})
|
|
13244
|
-
}
|
|
13245
|
-
]
|
|
13246
|
-
};
|
|
13247
|
-
}
|
|
13248
|
-
function createNotImplementedHandler(name) {
|
|
13249
|
-
return async () => toMcpError(
|
|
13250
|
-
new McpHandlerError(
|
|
13251
|
-
`Tool not implemented yet: ${name}`,
|
|
13252
|
-
"NOT_IMPLEMENTED",
|
|
13253
|
-
501
|
|
13254
|
-
)
|
|
13255
|
-
);
|
|
13256
|
-
}
|
|
13257
|
-
function validateRequired(params, contract) {
|
|
13258
|
-
for (const key of contract.required) {
|
|
13259
|
-
if (isMissing(params[key])) {
|
|
13260
|
-
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
13261
|
-
}
|
|
13262
|
-
}
|
|
13263
|
-
}
|
|
13264
|
-
function contractToHandler(contract, executor) {
|
|
13265
|
-
return async (params) => {
|
|
13266
|
-
try {
|
|
13267
|
-
validateRequired(params, contract);
|
|
13268
|
-
const payload = await executor(params);
|
|
13269
|
-
return toMcpResult(payload);
|
|
13270
|
-
} catch (error) {
|
|
13271
|
-
return toMcpError(error);
|
|
13272
|
-
}
|
|
13273
|
-
};
|
|
13274
|
-
}
|
|
13275
|
-
|
|
13276
|
-
// src/handlers/beliefs.ts
|
|
13277
|
-
var AMBIGUOUS_SCALAR_SUGGESTION = "Use opinion tuple (b, d, u, a) or an @lucern/sdk opinionFromBaseRate/opinionFromDogmatic/opinionFromProjected helper.";
|
|
13278
|
-
function readOpinionTuple(params) {
|
|
13279
|
-
const belief = readNumber2(params, "belief");
|
|
13280
|
-
const disbelief = readNumber2(params, "disbelief");
|
|
13281
|
-
const uncertainty = readNumber2(params, "uncertainty");
|
|
13282
|
-
const baseRate = readNumber2(params, "baseRate");
|
|
13283
|
-
const tupleValues = [belief, disbelief, uncertainty, baseRate];
|
|
13284
|
-
const providedCount = tupleValues.filter(
|
|
13285
|
-
(value) => value !== void 0
|
|
13286
|
-
).length;
|
|
13287
|
-
if (providedCount === 0) {
|
|
13288
|
-
if (readNumber2(params, "confidence") !== void 0) {
|
|
13289
|
-
throw new McpHandlerError(
|
|
13290
|
-
"Scalar confidence input is ambiguous without an explicit subjective-logic interpretation.",
|
|
13291
|
-
"AMBIGUOUS_SCALAR",
|
|
13292
|
-
400,
|
|
13293
|
-
AMBIGUOUS_SCALAR_SUGGESTION
|
|
13294
|
-
);
|
|
13295
|
-
}
|
|
13296
|
-
throw new McpHandlerError(
|
|
13297
|
-
"Missing required opinion tuple: belief, disbelief, uncertainty, and baseRate are required.",
|
|
13298
|
-
"INVALID_REQUEST",
|
|
13299
|
-
400
|
|
13300
|
-
);
|
|
13301
|
-
}
|
|
13302
|
-
if (providedCount !== tupleValues.length) {
|
|
13303
|
-
throw new McpHandlerError(
|
|
13304
|
-
"Incomplete opinion tuple: belief, disbelief, uncertainty, and baseRate must all be provided together.",
|
|
13305
|
-
"INVALID_REQUEST",
|
|
13306
|
-
400
|
|
13307
|
-
);
|
|
13308
|
-
}
|
|
13309
|
-
return {
|
|
13310
|
-
b: belief,
|
|
13311
|
-
d: disbelief,
|
|
13312
|
-
u: uncertainty,
|
|
13313
|
-
a: baseRate
|
|
13314
|
-
};
|
|
13315
|
-
}
|
|
13316
|
-
function createBeliefHandlers(context) {
|
|
13317
|
-
const beliefs = createBeliefsClient(context.sdkConfig);
|
|
13318
|
-
const graph = createGraphClient(context.sdkConfig);
|
|
13319
|
-
return {
|
|
13320
|
-
create_belief: contractToHandler(
|
|
13321
|
-
MCP_TOOL_CONTRACTS.create_belief,
|
|
13322
|
-
async (params) => {
|
|
13323
|
-
const result = await beliefs.createBelief({
|
|
13324
|
-
canonicalText: readString3(params, "canonicalText", {
|
|
13325
|
-
required: true
|
|
13326
|
-
}),
|
|
13327
|
-
topicId: readTopicId4(params, { required: true }),
|
|
13328
|
-
layer: readString3(params, "layer"),
|
|
13329
|
-
domain: readString3(params, "domain"),
|
|
13330
|
-
subtype: readString3(params, "nodeType"),
|
|
13331
|
-
baseRate: readNumber2(params, "baseRate", { required: true })
|
|
13332
|
-
});
|
|
13333
|
-
return {
|
|
13334
|
-
nodeId: result.data.nodeId,
|
|
13335
|
-
globalId: result.data.globalId,
|
|
13336
|
-
status: result.data.status ?? "unscored"
|
|
13337
|
-
};
|
|
13338
|
-
}
|
|
13339
|
-
),
|
|
13340
|
-
refine_belief: contractToHandler(
|
|
13341
|
-
MCP_TOOL_CONTRACTS.refine_belief,
|
|
13342
|
-
async (params) => {
|
|
13343
|
-
const nodeId = readString3(params, "nodeId", { required: true });
|
|
13344
|
-
const canonicalText = readString3(params, "canonicalText", {
|
|
13345
|
-
required: true
|
|
13346
|
-
});
|
|
13347
|
-
const rationale = readString3(params, "rationale");
|
|
13348
|
-
const result = await beliefs.refineBelief(nodeId, {
|
|
13349
|
-
canonicalText,
|
|
13350
|
-
rationale
|
|
13351
|
-
});
|
|
13352
|
-
return {
|
|
13353
|
-
nodeId: result.data.nodeId ?? nodeId,
|
|
13354
|
-
canonicalText: result.data.canonicalText ?? canonicalText,
|
|
13355
|
-
updatedAt: result.data.updatedAt ?? Date.now()
|
|
13356
|
-
};
|
|
13357
|
-
}
|
|
13358
|
-
),
|
|
13359
|
-
modulate_confidence: contractToHandler(
|
|
13360
|
-
MCP_TOOL_CONTRACTS.modulate_confidence,
|
|
13361
|
-
async (params) => {
|
|
13362
|
-
const nodeId = readString3(params, "nodeId", { required: true });
|
|
13363
|
-
const opinion = readOpinionTuple(params);
|
|
13364
|
-
const result = await beliefs.modulateConfidence(nodeId, {
|
|
13365
|
-
opinion,
|
|
13366
|
-
trigger: readString3(params, "trigger", { required: true }),
|
|
13367
|
-
rationale: readString3(params, "rationale", { required: true }),
|
|
13368
|
-
triggeringEvidenceId: readString3(params, "triggeringEvidenceId"),
|
|
13369
|
-
triggeringQuestionId: readString3(params, "triggeringQuestionId"),
|
|
13370
|
-
triggeringAnswerId: readString3(params, "triggeringAnswerId"),
|
|
13371
|
-
triggeringContradictionId: readString3(
|
|
13372
|
-
params,
|
|
13373
|
-
"triggeringContradictionId"
|
|
13374
|
-
),
|
|
13375
|
-
triggeringWorktreeId: readString3(params, "triggeringWorktreeId")
|
|
13376
|
-
});
|
|
13377
|
-
return {
|
|
13378
|
-
nodeId,
|
|
13379
|
-
newConfidence: result.data.newConfidence ?? result.data.confidence ?? opinion.b + opinion.a * opinion.u,
|
|
13380
|
-
previousConfidence: result.data.previousConfidence ?? null,
|
|
13381
|
-
trigger: readString3(params, "trigger", { required: true })
|
|
13382
|
-
};
|
|
13383
|
-
}
|
|
13384
|
-
),
|
|
13385
|
-
fork_belief: contractToHandler(
|
|
13386
|
-
MCP_TOOL_CONTRACTS.fork_belief,
|
|
13387
|
-
async (params) => {
|
|
13388
|
-
const nodeId = readString3(params, "nodeId", { required: true });
|
|
13389
|
-
const forkReason = readString3(params, "forkReason", {
|
|
13390
|
-
required: true
|
|
13391
|
-
});
|
|
13392
|
-
const result = await beliefs.forkBelief(nodeId, {
|
|
13393
|
-
newFormulation: readString3(params, "newFormulation", {
|
|
13394
|
-
required: true
|
|
13395
|
-
}),
|
|
13396
|
-
forkReason
|
|
13397
|
-
});
|
|
13398
|
-
return {
|
|
13399
|
-
nodeId: result.data.nodeId,
|
|
13400
|
-
parentNodeId: result.data.parentNodeId ?? nodeId,
|
|
13401
|
-
forkReason: result.data.forkReason ?? forkReason
|
|
13402
|
-
};
|
|
13403
|
-
}
|
|
13404
|
-
),
|
|
13405
|
-
archive_belief: contractToHandler(
|
|
13406
|
-
MCP_TOOL_CONTRACTS.archive_belief,
|
|
13407
|
-
async (params) => {
|
|
13408
|
-
const nodeId = readString3(params, "nodeId", { required: true });
|
|
13409
|
-
const rationale = readString3(params, "rationale");
|
|
13410
|
-
const result = await graph.updateNode({
|
|
13411
|
-
nodeId,
|
|
13412
|
-
status: "archived",
|
|
13413
|
-
metadata: rationale ? {
|
|
13414
|
-
archiveRationale: rationale
|
|
13415
|
-
} : void 0
|
|
13416
|
-
});
|
|
13417
|
-
return {
|
|
13418
|
-
nodeId: result.data.nodeId ?? nodeId,
|
|
13419
|
-
status: "archived"
|
|
13420
|
-
};
|
|
13421
|
-
}
|
|
13422
|
-
)
|
|
13423
|
-
};
|
|
13424
|
-
}
|
|
13425
|
-
|
|
13426
|
-
// src/handlers/context.ts
|
|
13427
|
-
function createContextHandlers(context) {
|
|
13428
|
-
const compiler = createContextClient(context.sdkConfig);
|
|
13429
|
-
return {
|
|
13430
|
-
compile_context: contractToHandler(
|
|
13431
|
-
MCP_TOOL_CONTRACTS.compile_context,
|
|
13432
|
-
async (params) => {
|
|
13433
|
-
const response = await compiler.compile(
|
|
13434
|
-
readTopicId4(params, { required: true }),
|
|
13435
|
-
{
|
|
13436
|
-
...readString3(params, "query") ? { query: readString3(params, "query") } : {},
|
|
13437
|
-
...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
|
|
13438
|
-
...readString3(params, "ranking") ? {
|
|
13439
|
-
ranking: readString3(params, "ranking")
|
|
13440
|
-
} : {},
|
|
13441
|
-
...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
|
|
13442
|
-
...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
|
|
13443
|
-
...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
|
|
13444
|
-
}
|
|
13445
|
-
);
|
|
13446
|
-
return response.data;
|
|
13447
|
-
}
|
|
13448
|
-
)
|
|
13449
|
-
};
|
|
13450
|
-
}
|
|
13451
|
-
|
|
13452
|
-
// src/handlers/contradictions.ts
|
|
13453
|
-
function createContradictionHandlers(context) {
|
|
13454
|
-
const lucern = createLucernClient(context.sdkConfig);
|
|
13455
|
-
return {
|
|
13456
|
-
flag_contradiction: contractToHandler(
|
|
13457
|
-
MCP_TOOL_CONTRACTS.flag_contradiction,
|
|
13458
|
-
async (params) => {
|
|
13459
|
-
const beliefA = readString3(params, "beliefA", { required: true });
|
|
13460
|
-
const beliefB = readString3(params, "beliefB", { required: true });
|
|
13461
|
-
const description = readString3(params, "description", {
|
|
13462
|
-
required: true
|
|
13463
|
-
});
|
|
13464
|
-
const topicId = readTopicId4(params, { required: true });
|
|
13465
|
-
const severity = readString3(params, "severity") ?? "medium";
|
|
13466
|
-
const defeatType = readString3(params, "defeatType") ?? "rebuts";
|
|
13467
|
-
const contradiction = await lucern.contradictions.flag({
|
|
13468
|
-
beliefA,
|
|
13469
|
-
beliefB,
|
|
13470
|
-
description,
|
|
13471
|
-
topicId,
|
|
13472
|
-
severity,
|
|
13473
|
-
defeatType
|
|
13474
|
-
});
|
|
13475
|
-
return {
|
|
13476
|
-
contradictionId: contradiction.contradictionId,
|
|
13477
|
-
status: contradiction.status,
|
|
13478
|
-
beliefA: contradiction.beliefA,
|
|
13479
|
-
beliefB: contradiction.beliefB
|
|
13480
|
-
};
|
|
13481
|
-
}
|
|
13482
|
-
)
|
|
13483
|
-
};
|
|
13484
|
-
}
|
|
13485
|
-
|
|
13486
|
-
// src/handlers/edges.ts
|
|
13487
|
-
function createEdgeHandlers(context) {
|
|
13488
|
-
const lucern = createLucernClient(context.sdkConfig);
|
|
13489
|
-
return {
|
|
13490
|
-
create_edge: contractToHandler(
|
|
13491
|
-
MCP_TOOL_CONTRACTS.create_edge,
|
|
13492
|
-
async (params) => {
|
|
13493
|
-
const sourceId = readString3(params, "sourceId", { required: true });
|
|
13494
|
-
const targetId = readString3(params, "targetId", { required: true });
|
|
13495
|
-
const edgeType = readString3(params, "edgeType", { required: true });
|
|
13496
|
-
const confidence = readNumber2(params, "confidence");
|
|
13497
|
-
const weight = readNumber2(params, "weight");
|
|
13498
|
-
const contextText = readString3(params, "context") ?? readString3(params, "reasoning");
|
|
13499
|
-
const edge = await lucern.edges.create({
|
|
13500
|
-
sourceId,
|
|
13501
|
-
targetId,
|
|
13502
|
-
edgeType,
|
|
13503
|
-
confidence,
|
|
13504
|
-
weight,
|
|
13505
|
-
context: contextText
|
|
13506
|
-
});
|
|
13507
|
-
return {
|
|
13508
|
-
globalId: edge.globalId ?? edge.edgeId ?? "",
|
|
13509
|
-
edgeType: edge.edgeType ?? edgeType,
|
|
13510
|
-
fromLayer: edge.fromLayer ?? "unknown",
|
|
13511
|
-
toLayer: edge.toLayer ?? "unknown"
|
|
13512
|
-
};
|
|
13513
|
-
}
|
|
13514
|
-
)
|
|
13515
|
-
};
|
|
13516
|
-
}
|
|
13517
|
-
|
|
13518
|
-
// src/handlers/evidence.ts
|
|
13519
|
-
function readMetadata(params) {
|
|
13520
|
-
const metadata = params.metadata;
|
|
13521
|
-
return metadata && typeof metadata === "object" && !Array.isArray(metadata) ? metadata : void 0;
|
|
13522
|
-
}
|
|
13523
|
-
function createEvidenceHandlers(context) {
|
|
13524
|
-
const lucern = createLucernClient(context.sdkConfig);
|
|
13525
|
-
return {
|
|
13526
|
-
create_evidence: contractToHandler(
|
|
13527
|
-
MCP_TOOL_CONTRACTS.create_evidence,
|
|
13528
|
-
async (params) => {
|
|
13529
|
-
const response = await lucern.evidence.create({
|
|
13530
|
-
topicId: readTopicId4(params, { required: true }),
|
|
13531
|
-
text: readString3(params, "text", { required: true }),
|
|
13532
|
-
source: readString3(params, "source"),
|
|
13533
|
-
targetId: readString3(params, "targetId"),
|
|
13534
|
-
weight: readNumber2(params, "weight"),
|
|
13535
|
-
metadata: readMetadata(params),
|
|
13536
|
-
title: readString3(params, "title"),
|
|
13537
|
-
content: readString3(params, "content"),
|
|
13538
|
-
contentType: readString3(params, "contentType"),
|
|
13539
|
-
kind: readString3(params, "kind")
|
|
13540
|
-
});
|
|
13541
|
-
return response.data;
|
|
13542
|
-
}
|
|
13543
|
-
),
|
|
13544
|
-
get_evidence: contractToHandler(
|
|
13545
|
-
MCP_TOOL_CONTRACTS.get_evidence,
|
|
13546
|
-
async (params) => {
|
|
13547
|
-
const response = await lucern.evidence.get(
|
|
13548
|
-
readString3(params, "id", { required: true })
|
|
13549
|
-
);
|
|
13550
|
-
return response.data;
|
|
13551
|
-
}
|
|
13552
|
-
),
|
|
13553
|
-
list_evidence: contractToHandler(
|
|
13554
|
-
MCP_TOOL_CONTRACTS.list_evidence,
|
|
13555
|
-
async (params) => {
|
|
13556
|
-
const response = await lucern.evidence.list({
|
|
13557
|
-
topicId: readTopicId4(params),
|
|
13558
|
-
targetId: readString3(params, "targetId"),
|
|
13559
|
-
limit: readNumber2(params, "limit"),
|
|
13560
|
-
cursor: readString3(params, "cursor")
|
|
13561
|
-
});
|
|
13562
|
-
return response.data;
|
|
13563
|
-
}
|
|
13564
|
-
),
|
|
13565
|
-
link_evidence: contractToHandler(
|
|
13566
|
-
MCP_TOOL_CONTRACTS.link_evidence,
|
|
13567
|
-
async (params) => {
|
|
13568
|
-
const response = await lucern.evidence.link({
|
|
13569
|
-
evidenceId: readString3(params, "evidenceId", { required: true }),
|
|
13570
|
-
targetId: readString3(params, "targetId", { required: true }),
|
|
13571
|
-
weight: readNumber2(params, "weight"),
|
|
13572
|
-
rationale: readString3(params, "rationale")
|
|
13573
|
-
});
|
|
13574
|
-
return response.data;
|
|
13575
|
-
}
|
|
13576
|
-
),
|
|
13577
|
-
search_evidence: contractToHandler(
|
|
13578
|
-
MCP_TOOL_CONTRACTS.search_evidence,
|
|
13579
|
-
async (params) => {
|
|
13580
|
-
const response = await lucern.evidence.search({
|
|
13581
|
-
q: readString3(params, "q") ?? readString3(params, "query", { required: true }),
|
|
13582
|
-
topicId: readTopicId4(params),
|
|
13583
|
-
targetId: readString3(params, "targetId"),
|
|
13584
|
-
limit: readNumber2(params, "limit"),
|
|
13585
|
-
cursor: readString3(params, "cursor")
|
|
13586
|
-
});
|
|
13587
|
-
return response.data;
|
|
13588
|
-
}
|
|
13589
|
-
),
|
|
13590
|
-
add_evidence: contractToHandler(
|
|
13591
|
-
MCP_TOOL_CONTRACTS.add_evidence,
|
|
13592
|
-
async (params) => {
|
|
13593
|
-
return lucern.evidence.add({
|
|
13594
|
-
canonicalText: readString3(params, "canonicalText", { required: true }),
|
|
13595
|
-
topicId: readTopicId4(params, { required: true }),
|
|
13596
|
-
sourceUrl: readString3(params, "sourceUrl"),
|
|
13597
|
-
supports: {
|
|
13598
|
-
nodeId: readString3(params, "targetNodeId", { required: true }),
|
|
13599
|
-
weight: readNumber2(params, "weight") ?? 1,
|
|
13600
|
-
reasoning: readString3(params, "reasoning")
|
|
13601
|
-
},
|
|
13602
|
-
title: readString3(params, "title"),
|
|
13603
|
-
content: readString3(params, "content"),
|
|
13604
|
-
contentType: readString3(params, "contentType"),
|
|
13605
|
-
metadata: readMetadata(params)
|
|
13606
|
-
});
|
|
13607
|
-
}
|
|
13608
|
-
),
|
|
13609
|
-
link_evidence_to_belief: contractToHandler(
|
|
13610
|
-
MCP_TOOL_CONTRACTS.link_evidence_to_belief,
|
|
13611
|
-
async (params) => {
|
|
13612
|
-
return lucern.evidence.linkToBelief({
|
|
13613
|
-
evidenceId: readString3(params, "evidenceId", { required: true }),
|
|
13614
|
-
beliefId: readString3(params, "beliefId", { required: true }),
|
|
13615
|
-
weight: readNumber2(params, "weight", { required: true }),
|
|
13616
|
-
rationale: readString3(params, "rationale")
|
|
13617
|
-
});
|
|
13618
|
-
}
|
|
13619
|
-
)
|
|
13620
|
-
};
|
|
13621
|
-
}
|
|
13622
|
-
|
|
13623
13449
|
// ../contracts/src/dsl/defineTable.ts
|
|
13624
13450
|
function defineTable(spec) {
|
|
13625
13451
|
return spec;
|
|
@@ -17454,7 +17280,9 @@ defineTable({
|
|
|
17454
17280
|
"defaultProjectVisibility": z.enum(["private", "team", "firm", "external", "public"]).optional(),
|
|
17455
17281
|
"deployments": z.record(z.object({
|
|
17456
17282
|
"url": z.string(),
|
|
17457
|
-
"
|
|
17283
|
+
"target": z.enum(["kernelDeployment", "appDeployment"]).optional(),
|
|
17284
|
+
"encryptedDeployKey": z.string().optional(),
|
|
17285
|
+
"credentialRef": z.string().optional()
|
|
17458
17286
|
})).optional(),
|
|
17459
17287
|
"metadata": z.record(z.any()).optional(),
|
|
17460
17288
|
"createdBy": z.string().optional(),
|
|
@@ -18517,8 +18345,31 @@ function assertSurfaceCoverage(contracts) {
|
|
|
18517
18345
|
}
|
|
18518
18346
|
}
|
|
18519
18347
|
}
|
|
18520
|
-
|
|
18521
|
-
|
|
18348
|
+
var jsonRecordSchema2 = z.record(z.unknown());
|
|
18349
|
+
var observationArgs = z.object({
|
|
18350
|
+
topicId: z.string().optional().describe("Topic scope for the observation."),
|
|
18351
|
+
summary: z.string().describe("Short observation summary."),
|
|
18352
|
+
text: z.string().optional().describe("Canonical observation text alias."),
|
|
18353
|
+
title: z.string().optional().describe("Optional observation title."),
|
|
18354
|
+
content: z.string().optional().describe("Optional rich observation content."),
|
|
18355
|
+
contentType: z.string().optional().describe("Observation content type."),
|
|
18356
|
+
kind: z.string().optional().describe("Evidence kind to store."),
|
|
18357
|
+
observationType: z.string().optional().describe("Observation type."),
|
|
18358
|
+
tags: z.array(z.string()).optional().describe("Observation tags."),
|
|
18359
|
+
source: z.string().optional().describe("Observation source label."),
|
|
18360
|
+
sourceType: z.string().optional().describe("Evidence source type."),
|
|
18361
|
+
externalSourceType: z.string().optional().describe("External source type for imported observations."),
|
|
18362
|
+
sourceUrl: z.string().optional().describe("Canonical source URL."),
|
|
18363
|
+
confidence: z.number().optional().describe("Observation confidence."),
|
|
18364
|
+
metadata: jsonRecordSchema2.optional().describe("Observation metadata."),
|
|
18365
|
+
rationale: z.string().optional().describe("Why this observation should be recorded.")
|
|
18366
|
+
});
|
|
18367
|
+
var observationContextArgs = z.object({
|
|
18368
|
+
topicId: z.string().describe("Topic scope."),
|
|
18369
|
+
query: z.string().optional().describe("Optional context query."),
|
|
18370
|
+
limit: z.number().optional().describe("Maximum observations to return."),
|
|
18371
|
+
status: z.string().optional().describe("Observation status filter.")
|
|
18372
|
+
});
|
|
18522
18373
|
var observationInput = (input, context) => withUserId(
|
|
18523
18374
|
compactRecord4({
|
|
18524
18375
|
projectId: input.projectId,
|
|
@@ -18577,7 +18428,8 @@ var contextContracts = [
|
|
|
18577
18428
|
observationId: output && typeof output === "object" ? output.nodeId : void 0,
|
|
18578
18429
|
observationType: input.observationType
|
|
18579
18430
|
})
|
|
18580
|
-
}
|
|
18431
|
+
},
|
|
18432
|
+
args: observationArgs
|
|
18581
18433
|
}),
|
|
18582
18434
|
surfaceContract({
|
|
18583
18435
|
name: "get_observation_context",
|
|
@@ -18598,7 +18450,8 @@ var contextContracts = [
|
|
|
18598
18450
|
status: input.status,
|
|
18599
18451
|
userId: input.userId
|
|
18600
18452
|
})
|
|
18601
|
-
}
|
|
18453
|
+
},
|
|
18454
|
+
args: observationContextArgs
|
|
18602
18455
|
})
|
|
18603
18456
|
];
|
|
18604
18457
|
|
|
@@ -18661,8 +18514,45 @@ var identityContracts = [
|
|
|
18661
18514
|
}
|
|
18662
18515
|
})
|
|
18663
18516
|
];
|
|
18664
|
-
|
|
18665
|
-
|
|
18517
|
+
var jsonRecordSchema3 = z.record(z.unknown());
|
|
18518
|
+
var sourceTypeSchema = z.enum(["human", "ai_extracted", "ai_generated"]);
|
|
18519
|
+
var reversibilitySchema = z.enum([
|
|
18520
|
+
"irreversible",
|
|
18521
|
+
"hard_to_reverse",
|
|
18522
|
+
"reversible",
|
|
18523
|
+
"trivial"
|
|
18524
|
+
]);
|
|
18525
|
+
var predictionMetaSchema = z.object({
|
|
18526
|
+
isPrediction: z.boolean().describe("Whether this belief is a prediction."),
|
|
18527
|
+
registeredAt: z.number().describe("Timestamp when the prediction was registered."),
|
|
18528
|
+
expectedBy: z.number().optional().describe("Timestamp when the prediction should be evaluated.")
|
|
18529
|
+
});
|
|
18530
|
+
var createBeliefArgs = z.object({
|
|
18531
|
+
canonicalText: z.string().describe("The belief statement the agent holds to be true."),
|
|
18532
|
+
topicId: z.string().optional().describe("Topic scope hint for the belief."),
|
|
18533
|
+
baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
|
|
18534
|
+
beliefType: z.string().optional().describe("Schema belief type."),
|
|
18535
|
+
metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
|
|
18536
|
+
rationale: z.string().optional().describe("Why this belief should enter the reasoning graph."),
|
|
18537
|
+
pillar: z.string().optional().describe("Innovation pillar or product pillar associated with the belief."),
|
|
18538
|
+
worktreeId: z.string().optional().describe("Worktree responsible for creating or testing this belief."),
|
|
18539
|
+
sourceBeliefIds: z.array(z.string()).optional().describe("Source belief IDs this belief derives from."),
|
|
18540
|
+
sourceType: sourceTypeSchema.optional().describe("Actor/source class that produced the belief."),
|
|
18541
|
+
reversibility: reversibilitySchema.optional().describe("How reversible the belief's implied decision is."),
|
|
18542
|
+
predictionMeta: predictionMetaSchema.optional().describe("Prediction lifecycle metadata when this belief is a forecast.")
|
|
18543
|
+
});
|
|
18544
|
+
var forkBeliefArgs = z.object({
|
|
18545
|
+
nodeId: z.string().describe("The scored belief to fork from."),
|
|
18546
|
+
newFormulation: z.string().describe("The evolved belief statement."),
|
|
18547
|
+
forkReason: z.enum([
|
|
18548
|
+
"refinement",
|
|
18549
|
+
"contradiction_response",
|
|
18550
|
+
"scope_change",
|
|
18551
|
+
"confidence_collapse",
|
|
18552
|
+
"manual"
|
|
18553
|
+
]).describe("Why this fork was created."),
|
|
18554
|
+
rationale: z.string().optional().describe("Why the fork is warranted.")
|
|
18555
|
+
});
|
|
18666
18556
|
var beliefLookupInput = (input) => compactRecord4({
|
|
18667
18557
|
nodeId: input.nodeId ?? input.id ?? input.beliefId,
|
|
18668
18558
|
beliefId: input.beliefId
|
|
@@ -18737,7 +18627,8 @@ var beliefsContracts = [
|
|
|
18737
18627
|
functionName: "create",
|
|
18738
18628
|
kind: "mutation",
|
|
18739
18629
|
inputProjection: createBeliefInput
|
|
18740
|
-
}
|
|
18630
|
+
},
|
|
18631
|
+
args: createBeliefArgs
|
|
18741
18632
|
}),
|
|
18742
18633
|
surfaceContract({
|
|
18743
18634
|
name: "get_belief",
|
|
@@ -18828,7 +18719,8 @@ var beliefsContracts = [
|
|
|
18828
18719
|
functionName: "forkBelief",
|
|
18829
18720
|
kind: "mutation",
|
|
18830
18721
|
inputProjection: forkBeliefInput
|
|
18831
|
-
}
|
|
18722
|
+
},
|
|
18723
|
+
args: forkBeliefArgs
|
|
18832
18724
|
}),
|
|
18833
18725
|
surfaceContract({
|
|
18834
18726
|
name: "archive_belief",
|
|
@@ -18909,8 +18801,46 @@ var beliefsContracts = [
|
|
|
18909
18801
|
}
|
|
18910
18802
|
})
|
|
18911
18803
|
];
|
|
18912
|
-
|
|
18913
|
-
|
|
18804
|
+
var jsonRecordSchema4 = z.record(z.unknown());
|
|
18805
|
+
var evidenceRelationSchema = z.enum(["supports", "contradicts", "neutral"]);
|
|
18806
|
+
var createEvidenceArgs = z.object({
|
|
18807
|
+
topicId: z.string().optional().describe("Topic scope for the evidence."),
|
|
18808
|
+
text: z.string().describe("Canonical evidence text."),
|
|
18809
|
+
source: z.string().optional().describe("Source URL or source label."),
|
|
18810
|
+
sourceUrl: z.string().optional().describe("Canonical source URL."),
|
|
18811
|
+
targetId: z.string().optional().describe("Belief or question identifier to link immediately."),
|
|
18812
|
+
linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
|
|
18813
|
+
evidenceRelation: evidenceRelationSchema.optional().describe("How the evidence relates to the linked belief."),
|
|
18814
|
+
confidence: z.number().optional().describe("Confidence in the evidence relation."),
|
|
18815
|
+
weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
|
|
18816
|
+
metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
|
|
18817
|
+
rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
|
|
18818
|
+
reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
|
|
18819
|
+
title: z.string().optional().describe("Optional short title."),
|
|
18820
|
+
content: z.string().optional().describe("Optional long-form content."),
|
|
18821
|
+
contentType: z.string().optional().describe("Content format or MIME hint."),
|
|
18822
|
+
kind: z.string().optional().describe("Evidence kind."),
|
|
18823
|
+
tags: z.array(z.string()).optional().describe("Evidence tags."),
|
|
18824
|
+
sourceType: z.string().optional().describe("Evidence source type."),
|
|
18825
|
+
externalSourceType: z.string().optional().describe("External source type for imported evidence."),
|
|
18826
|
+
sourceQuestionId: z.string().optional().describe("Question that sourced this evidence."),
|
|
18827
|
+
methodology: z.string().optional().describe("Collection methodology."),
|
|
18828
|
+
informationAsymmetry: z.string().optional().describe("Information asymmetry class."),
|
|
18829
|
+
sourceDescription: z.string().optional().describe("Human-readable source description.")
|
|
18830
|
+
});
|
|
18831
|
+
var addEvidenceArgs = z.object({
|
|
18832
|
+
canonicalText: z.string().describe("The evidence statement."),
|
|
18833
|
+
text: z.string().optional().describe("Canonical evidence text alias used by newer callers."),
|
|
18834
|
+
topicId: z.string().optional().describe("Topic scope hint."),
|
|
18835
|
+
sourceUrl: z.string().optional().describe("URL of the source material."),
|
|
18836
|
+
targetNodeId: z.string().describe("The belief this evidence bears on."),
|
|
18837
|
+
weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
|
|
18838
|
+
reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
|
|
18839
|
+
title: z.string().optional().describe("Optional short title."),
|
|
18840
|
+
content: z.string().optional().describe("Optional long-form evidence content."),
|
|
18841
|
+
contentType: z.string().optional().describe("Content format or MIME hint."),
|
|
18842
|
+
metadata: jsonRecordSchema4.optional().describe("Optional metadata merged into the evidence node.")
|
|
18843
|
+
});
|
|
18914
18844
|
var evidenceIdInput = (input) => compactRecord4({
|
|
18915
18845
|
evidenceId: input.evidenceId,
|
|
18916
18846
|
insightId: input.insightId,
|
|
@@ -18985,7 +18915,8 @@ var evidenceContracts = [
|
|
|
18985
18915
|
functionName: "create",
|
|
18986
18916
|
kind: "mutation",
|
|
18987
18917
|
inputProjection: createEvidenceInput
|
|
18988
|
-
}
|
|
18918
|
+
},
|
|
18919
|
+
args: createEvidenceArgs
|
|
18989
18920
|
}),
|
|
18990
18921
|
surfaceContract({
|
|
18991
18922
|
name: "add_evidence",
|
|
@@ -19021,7 +18952,8 @@ var evidenceContracts = [
|
|
|
19021
18952
|
context
|
|
19022
18953
|
);
|
|
19023
18954
|
}
|
|
19024
|
-
}
|
|
18955
|
+
},
|
|
18956
|
+
args: addEvidenceArgs
|
|
19025
18957
|
}),
|
|
19026
18958
|
surfaceContract({
|
|
19027
18959
|
name: "get_evidence",
|
|
@@ -19128,8 +19060,91 @@ var evidenceContracts = [
|
|
|
19128
19060
|
}
|
|
19129
19061
|
})
|
|
19130
19062
|
];
|
|
19131
|
-
|
|
19132
|
-
|
|
19063
|
+
var jsonRecordSchema5 = z.record(z.unknown());
|
|
19064
|
+
var questionPrioritySchema = z.enum(["urgent", "high", "medium", "low"]);
|
|
19065
|
+
var kernelQuestionPrioritySchema = z.enum([
|
|
19066
|
+
"critical",
|
|
19067
|
+
"high",
|
|
19068
|
+
"medium",
|
|
19069
|
+
"low"
|
|
19070
|
+
]);
|
|
19071
|
+
var questionTypeSchema = z.enum([
|
|
19072
|
+
"validation",
|
|
19073
|
+
"falsification",
|
|
19074
|
+
"assumption_probe",
|
|
19075
|
+
"prediction_test",
|
|
19076
|
+
"counterfactual",
|
|
19077
|
+
"discovery",
|
|
19078
|
+
"clarification",
|
|
19079
|
+
"comparison",
|
|
19080
|
+
"causal",
|
|
19081
|
+
"mechanism",
|
|
19082
|
+
"general"
|
|
19083
|
+
]);
|
|
19084
|
+
var createQuestionArgs = z.object({
|
|
19085
|
+
text: z.string().describe("The question text."),
|
|
19086
|
+
question: z.string().optional().describe("Backend question text alias for kernel-native callers."),
|
|
19087
|
+
topicId: z.string().optional().describe("Topic scope hint."),
|
|
19088
|
+
priority: questionPrioritySchema.optional().describe("Human-facing question priority."),
|
|
19089
|
+
linkedBeliefId: z.string().optional().describe("Belief this question tests."),
|
|
19090
|
+
linkedBeliefNodeId: z.string().optional().describe("Belief node this question tests."),
|
|
19091
|
+
metadata: jsonRecordSchema5.optional().describe("Optional metadata merged into the question record."),
|
|
19092
|
+
category: z.string().optional().describe("Question category."),
|
|
19093
|
+
source: z.string().optional().describe("Question source."),
|
|
19094
|
+
testType: z.enum(["validates", "invalidates", "clarifies"]).optional().describe("How this question tests its linked belief."),
|
|
19095
|
+
importance: z.number().optional().describe("Numeric importance score."),
|
|
19096
|
+
epistemicUnlock: z.string().optional().describe("What this question unlocks if answered."),
|
|
19097
|
+
sourceQuestionIds: z.array(z.string()).optional().describe("Question IDs this question derives from."),
|
|
19098
|
+
linkedWorktreeId: z.string().optional().describe("Worktree this question belongs to."),
|
|
19099
|
+
questionType: questionTypeSchema.optional().describe("Question type."),
|
|
19100
|
+
questionPriority: kernelQuestionPrioritySchema.optional().describe("Kernel-native question priority.")
|
|
19101
|
+
});
|
|
19102
|
+
var refineQuestionArgs = z.object({
|
|
19103
|
+
id: z.string().describe("The question to refine."),
|
|
19104
|
+
text: z.string().describe("Updated question text."),
|
|
19105
|
+
question: z.string().optional().describe("Backend question text alias for kernel-native callers."),
|
|
19106
|
+
rationale: z.string().optional().describe("Why the question is refined."),
|
|
19107
|
+
category: z.string().optional().describe("Updated question category."),
|
|
19108
|
+
priority: questionPrioritySchema.optional().describe("Updated human-facing priority.")
|
|
19109
|
+
});
|
|
19110
|
+
var createAnswerArgs = z.object({
|
|
19111
|
+
questionNodeId: z.string().describe("The question node ID this answer responds to."),
|
|
19112
|
+
questionId: z.string().optional().describe("Question ID alias accepted by the projection."),
|
|
19113
|
+
answerText: z.string().describe("The answer content."),
|
|
19114
|
+
topicId: z.string().optional().describe("Topic scope for the answer."),
|
|
19115
|
+
confidence: z.string().optional().describe("Answer confidence."),
|
|
19116
|
+
evidenceNodeIds: z.array(z.string()).optional().describe("Evidence node IDs supporting the answer."),
|
|
19117
|
+
answerSource: z.string().optional().describe("How the answer was produced."),
|
|
19118
|
+
worktreeId: z.string().optional().describe("Worktree whose outcome produced this answer."),
|
|
19119
|
+
sprintId: z.string().optional().describe("Legacy sprint identifier.")
|
|
19120
|
+
});
|
|
19121
|
+
var answerQuestionArgs = z.object({
|
|
19122
|
+
id: z.string().describe("Canonical question ID."),
|
|
19123
|
+
topicId: z.string().describe("Topic scope for the answer."),
|
|
19124
|
+
text: z.string().describe("Answer text."),
|
|
19125
|
+
confidence: z.enum(["weak", "medium", "strong"]).optional().describe("Optional answer confidence."),
|
|
19126
|
+
evidenceIds: z.array(z.string()).optional().describe("Canonical evidence IDs supporting the answer."),
|
|
19127
|
+
rationale: z.string().optional().describe("Why this answer is credible."),
|
|
19128
|
+
questionId: z.string().optional().describe("Question ID alias accepted by the projection."),
|
|
19129
|
+
questionNodeId: z.string().optional().describe("Question node ID alias accepted by the projection."),
|
|
19130
|
+
answerText: z.string().optional().describe("Canonical answer text alias accepted by newer callers."),
|
|
19131
|
+
evidenceNodeIds: z.array(z.string()).optional().describe("Evidence node ID alias accepted by newer callers."),
|
|
19132
|
+
answerSource: z.string().optional().describe("How the answer was produced."),
|
|
19133
|
+
worktreeId: z.string().optional().describe("Worktree whose outcome produced this answer."),
|
|
19134
|
+
sprintId: z.string().optional().describe("Legacy sprint identifier.")
|
|
19135
|
+
});
|
|
19136
|
+
var missingQuestionsArgs = z.object({
|
|
19137
|
+
topicId: z.string().describe("Topic scope."),
|
|
19138
|
+
minConfidence: z.number().optional().describe("Minimum confidence threshold for missing-question checks."),
|
|
19139
|
+
status: z.string().optional().describe("Question status filter."),
|
|
19140
|
+
limit: z.number().optional().describe("Maximum questions to inspect.")
|
|
19141
|
+
});
|
|
19142
|
+
var falsificationQuestionsArgs = z.object({
|
|
19143
|
+
topicId: z.string().describe("Topic scope."),
|
|
19144
|
+
beliefIds: z.array(z.string()).optional().describe("Beliefs to generate falsification questions for."),
|
|
19145
|
+
status: z.string().optional().describe("Question status filter."),
|
|
19146
|
+
limit: z.number().optional().describe("Maximum questions to inspect.")
|
|
19147
|
+
});
|
|
19133
19148
|
var questionNodeInput = (input) => compactRecord4({
|
|
19134
19149
|
nodeId: input.nodeId ?? input.id ?? input.questionId,
|
|
19135
19150
|
questionId: input.questionId
|
|
@@ -19176,7 +19191,8 @@ var questionsContracts = [
|
|
|
19176
19191
|
functionName: "create",
|
|
19177
19192
|
kind: "mutation",
|
|
19178
19193
|
inputProjection: createQuestionInput
|
|
19179
|
-
}
|
|
19194
|
+
},
|
|
19195
|
+
args: createQuestionArgs
|
|
19180
19196
|
}),
|
|
19181
19197
|
surfaceContract({
|
|
19182
19198
|
name: "get_question",
|
|
@@ -19232,7 +19248,8 @@ var questionsContracts = [
|
|
|
19232
19248
|
category: input.category,
|
|
19233
19249
|
priority: input.priority
|
|
19234
19250
|
})
|
|
19235
|
-
}
|
|
19251
|
+
},
|
|
19252
|
+
args: refineQuestionArgs
|
|
19236
19253
|
}),
|
|
19237
19254
|
surfaceContract({
|
|
19238
19255
|
name: "update_question_status",
|
|
@@ -19308,7 +19325,8 @@ var questionsContracts = [
|
|
|
19308
19325
|
}),
|
|
19309
19326
|
context
|
|
19310
19327
|
)
|
|
19311
|
-
}
|
|
19328
|
+
},
|
|
19329
|
+
args: createAnswerArgs
|
|
19312
19330
|
}),
|
|
19313
19331
|
surfaceContract({
|
|
19314
19332
|
name: "answer_question",
|
|
@@ -19337,7 +19355,8 @@ var questionsContracts = [
|
|
|
19337
19355
|
}),
|
|
19338
19356
|
context
|
|
19339
19357
|
)
|
|
19340
|
-
}
|
|
19358
|
+
},
|
|
19359
|
+
args: answerQuestionArgs
|
|
19341
19360
|
}),
|
|
19342
19361
|
surfaceContract({
|
|
19343
19362
|
name: "get_answer",
|
|
@@ -19369,7 +19388,8 @@ var questionsContracts = [
|
|
|
19369
19388
|
functionName: "getByTopic",
|
|
19370
19389
|
kind: "query",
|
|
19371
19390
|
inputProjection: questionTopicInput
|
|
19372
|
-
}
|
|
19391
|
+
},
|
|
19392
|
+
args: missingQuestionsArgs
|
|
19373
19393
|
}),
|
|
19374
19394
|
surfaceContract({
|
|
19375
19395
|
name: "get_high_priority_questions",
|
|
@@ -19404,11 +19424,22 @@ var questionsContracts = [
|
|
|
19404
19424
|
functionName: "getByTopic",
|
|
19405
19425
|
kind: "query",
|
|
19406
19426
|
inputProjection: questionTopicInput
|
|
19407
|
-
}
|
|
19427
|
+
},
|
|
19428
|
+
args: falsificationQuestionsArgs
|
|
19408
19429
|
})
|
|
19409
19430
|
];
|
|
19410
|
-
|
|
19411
|
-
|
|
19431
|
+
var updateTopicArgs = z.object({
|
|
19432
|
+
id: z.string().describe("Topic ID."),
|
|
19433
|
+
topicId: z.string().optional().describe("Topic ID alias."),
|
|
19434
|
+
name: z.string().optional().describe("Topic name."),
|
|
19435
|
+
description: z.string().optional().describe("Topic description."),
|
|
19436
|
+
type: z.string().optional().describe("Topic type."),
|
|
19437
|
+
status: z.string().optional().describe("Topic status."),
|
|
19438
|
+
visibility: z.string().optional().describe("Topic visibility."),
|
|
19439
|
+
ontologyId: z.string().optional().describe("Ontology to bind."),
|
|
19440
|
+
clearOntologyId: z.boolean().optional().describe("Whether to clear the ontology binding."),
|
|
19441
|
+
metadata: z.record(z.unknown()).optional().describe("Topic metadata.")
|
|
19442
|
+
});
|
|
19412
19443
|
var topicIdInput = (input) => compactRecord4({
|
|
19413
19444
|
id: input.id ?? input.topicId
|
|
19414
19445
|
});
|
|
@@ -19489,7 +19520,8 @@ var topicsContracts = [
|
|
|
19489
19520
|
functionName: "update",
|
|
19490
19521
|
kind: "mutation",
|
|
19491
19522
|
inputProjection: updateTopicInput
|
|
19492
|
-
}
|
|
19523
|
+
},
|
|
19524
|
+
args: updateTopicArgs
|
|
19493
19525
|
}),
|
|
19494
19526
|
surfaceContract({
|
|
19495
19527
|
name: "get_topic_tree",
|
|
@@ -19508,8 +19540,27 @@ var topicsContracts = [
|
|
|
19508
19540
|
}
|
|
19509
19541
|
})
|
|
19510
19542
|
];
|
|
19511
|
-
|
|
19512
|
-
|
|
19543
|
+
var lensPerspectiveSchema = z.enum([
|
|
19544
|
+
"investigation",
|
|
19545
|
+
"monitoring",
|
|
19546
|
+
"analysis",
|
|
19547
|
+
"comparison",
|
|
19548
|
+
"taxonomy"
|
|
19549
|
+
]);
|
|
19550
|
+
var jsonRecordSchema6 = z.record(z.unknown());
|
|
19551
|
+
var createLensArgs = z.object({
|
|
19552
|
+
name: z.string().describe("Lens name."),
|
|
19553
|
+
workspaceId: z.string().optional().describe("Workspace scope for the lens."),
|
|
19554
|
+
topicId: z.string().optional().describe("Originating topic scope."),
|
|
19555
|
+
description: z.string().optional().describe("What this lens investigates or monitors."),
|
|
19556
|
+
perspectiveType: lensPerspectiveSchema.describe("Perspective type."),
|
|
19557
|
+
promptTemplates: z.array(jsonRecordSchema6).optional().describe("Prompt templates used through this lens."),
|
|
19558
|
+
workflowTemplates: z.array(jsonRecordSchema6).optional().describe("Guided workflow templates."),
|
|
19559
|
+
taskTemplates: z.array(jsonRecordSchema6).optional().describe("Default task templates."),
|
|
19560
|
+
questionTemplates: z.array(jsonRecordSchema6).optional().describe("Default question templates."),
|
|
19561
|
+
filterCriteria: jsonRecordSchema6.optional().describe("Belief/evidence filtering criteria."),
|
|
19562
|
+
metadata: jsonRecordSchema6.optional().describe("Additional lens metadata.")
|
|
19563
|
+
});
|
|
19513
19564
|
var createLensInput = (input, context) => compactRecord4({
|
|
19514
19565
|
name: input.name,
|
|
19515
19566
|
description: input.description,
|
|
@@ -19546,7 +19597,8 @@ var lensesContracts = [
|
|
|
19546
19597
|
functionName: "create",
|
|
19547
19598
|
kind: "mutation",
|
|
19548
19599
|
inputProjection: createLensInput
|
|
19549
|
-
}
|
|
19600
|
+
},
|
|
19601
|
+
args: createLensArgs
|
|
19550
19602
|
}),
|
|
19551
19603
|
surfaceContract({
|
|
19552
19604
|
name: "list_lenses",
|
|
@@ -19608,8 +19660,18 @@ var lensesContracts = [
|
|
|
19608
19660
|
}
|
|
19609
19661
|
})
|
|
19610
19662
|
];
|
|
19611
|
-
|
|
19612
|
-
|
|
19663
|
+
var updateOntologyArgs = z.object({
|
|
19664
|
+
id: z.string().describe("Ontology definition ID."),
|
|
19665
|
+
ontologyId: z.string().optional().describe("Ontology ID alias."),
|
|
19666
|
+
name: z.string().optional().describe("Ontology display name."),
|
|
19667
|
+
description: z.string().optional().describe("Ontology description."),
|
|
19668
|
+
status: z.string().optional().describe("Ontology lifecycle status.")
|
|
19669
|
+
});
|
|
19670
|
+
var ontologyVersionLifecycleArgs = z.object({
|
|
19671
|
+
id: z.string().describe("Ontology version ID."),
|
|
19672
|
+
versionId: z.string().optional().describe("Ontology version ID alias."),
|
|
19673
|
+
ontologyId: z.string().optional().describe("Ontology definition ID.")
|
|
19674
|
+
});
|
|
19613
19675
|
var ontologyIdInput = (input) => compactRecord4({
|
|
19614
19676
|
id: input.id ?? input.ontologyId
|
|
19615
19677
|
});
|
|
@@ -19688,11 +19750,11 @@ var ontologiesContracts = [
|
|
|
19688
19750
|
id: input.id ?? input.ontologyId,
|
|
19689
19751
|
name: input.name,
|
|
19690
19752
|
description: input.description,
|
|
19691
|
-
parentOntologyId: input.parentOntologyId,
|
|
19692
19753
|
status: input.status,
|
|
19693
19754
|
actorId: input.actorId
|
|
19694
19755
|
})
|
|
19695
|
-
}
|
|
19756
|
+
},
|
|
19757
|
+
args: updateOntologyArgs
|
|
19696
19758
|
}),
|
|
19697
19759
|
surfaceContract({
|
|
19698
19760
|
name: "archive_ontology",
|
|
@@ -19775,7 +19837,8 @@ var ontologiesContracts = [
|
|
|
19775
19837
|
functionName: "publishOntologyVersion",
|
|
19776
19838
|
kind: "mutation",
|
|
19777
19839
|
inputProjection: ontologyVersionIdInput
|
|
19778
|
-
}
|
|
19840
|
+
},
|
|
19841
|
+
args: ontologyVersionLifecycleArgs
|
|
19779
19842
|
}),
|
|
19780
19843
|
surfaceContract({
|
|
19781
19844
|
name: "deprecate_ontology_version",
|
|
@@ -19791,7 +19854,8 @@ var ontologiesContracts = [
|
|
|
19791
19854
|
functionName: "deprecateOntologyVersion",
|
|
19792
19855
|
kind: "mutation",
|
|
19793
19856
|
inputProjection: ontologyVersionIdInput
|
|
19794
|
-
}
|
|
19857
|
+
},
|
|
19858
|
+
args: ontologyVersionLifecycleArgs
|
|
19795
19859
|
}),
|
|
19796
19860
|
surfaceContract({
|
|
19797
19861
|
name: "resolve_effective_ontology",
|
|
@@ -19810,8 +19874,76 @@ var ontologiesContracts = [
|
|
|
19810
19874
|
}
|
|
19811
19875
|
})
|
|
19812
19876
|
];
|
|
19813
|
-
|
|
19814
|
-
|
|
19877
|
+
var autoFixPolicyInputSchema = z.object({
|
|
19878
|
+
enabled: z.boolean().optional().describe("Whether automatic remediation is enabled."),
|
|
19879
|
+
mode: z.string().optional().describe("Automation mode for worktree auto-fixes."),
|
|
19880
|
+
maxAttempts: z.number().optional().describe("Maximum number of auto-fix attempts."),
|
|
19881
|
+
reviewer: z.string().optional().describe("Reviewer responsible for auto-fix oversight."),
|
|
19882
|
+
maxActionsPerRun: z.number().optional().describe("Maximum number of auto-fix actions per run."),
|
|
19883
|
+
permittedMutationTiers: z.array(z.enum(["read_only", "low_risk_write", "high_risk_write"])).optional().describe("Mutation tiers the auto-fix worker may execute."),
|
|
19884
|
+
requireAuditTrail: z.boolean().optional().describe("Whether auto-fix actions must write an audit trail."),
|
|
19885
|
+
escalationGate: z.string().optional().describe("Gate to trigger when auto-fix policy requires escalation.")
|
|
19886
|
+
}).passthrough().describe("Policy for permitted automatic remediation inside the worktree.");
|
|
19887
|
+
var worktreeKeyQuestionInputSchema = z.object({
|
|
19888
|
+
question: z.string().describe("Question the worktree must resolve."),
|
|
19889
|
+
status: z.enum(["open", "answered", "forked"]).optional().describe("Current disposition of the key question."),
|
|
19890
|
+
answer: z.string().optional().describe("Captured answer when the key question is resolved."),
|
|
19891
|
+
answerConfidence: z.enum(["high", "medium", "low"]).optional().describe("Confidence in the captured answer."),
|
|
19892
|
+
linkedQuestionId: z.string().optional().describe("Canonical question node linked to this key question.")
|
|
19893
|
+
}).passthrough().describe("Question contract embedded in the worktree plan.");
|
|
19894
|
+
var worktreeEvidenceSignalInputSchema = z.object({
|
|
19895
|
+
signal: z.string().describe("Evidence signal the worktree should collect."),
|
|
19896
|
+
collected: z.boolean().optional().describe("Whether the signal has already been collected."),
|
|
19897
|
+
progress: z.string().optional().describe("Collection progress note for the signal."),
|
|
19898
|
+
notes: z.string().optional().describe("Additional evidence collection notes.")
|
|
19899
|
+
}).passthrough().describe("Evidence signal embedded in the worktree plan.");
|
|
19900
|
+
var worktreeDecisionGateInputSchema = z.object({
|
|
19901
|
+
goCriteria: z.array(z.string()).describe("Criteria that must hold for the worktree to proceed."),
|
|
19902
|
+
noGoSignals: z.array(z.string()).describe("Signals that stop or redirect the worktree."),
|
|
19903
|
+
verdict: z.enum(["go", "no_go", "pivot", "pending"]).optional().describe("Current decision verdict for the worktree gate."),
|
|
19904
|
+
verdictRationale: z.string().optional().describe("Rationale supporting the current gate verdict."),
|
|
19905
|
+
decidedAt: z.number().optional().describe("Timestamp when the gate verdict was decided."),
|
|
19906
|
+
decidedBy: z.string().optional().describe("Actor that decided the gate verdict.")
|
|
19907
|
+
}).passthrough().describe("Decision gate contract for worktree activation or exit.");
|
|
19908
|
+
var addWorktreeArgs = z.object({
|
|
19909
|
+
title: z.string().optional().describe("Human-readable worktree name or objective."),
|
|
19910
|
+
name: z.string().optional().describe("Storage-name alias for callers that already use backend naming."),
|
|
19911
|
+
topicId: z.string().describe("Primary topic scope for the worktree."),
|
|
19912
|
+
projectId: z.string().optional().describe("Legacy topicId alias."),
|
|
19913
|
+
branchId: z.string().optional().describe("Legacy branch identifier for compatibility with workflow callers."),
|
|
19914
|
+
objective: z.string().optional().describe("Reasoning objective this worktree is intended to resolve."),
|
|
19915
|
+
hypothesis: z.string().optional().describe("Testable claim this worktree investigates."),
|
|
19916
|
+
rationale: z.string().optional().describe("Why this worktree exists and why it belongs in the campaign."),
|
|
19917
|
+
worktreeType: z.string().optional().describe("Schema-enum worktree type used for kernel lifecycle behavior."),
|
|
19918
|
+
gate: z.string().optional().describe("Exit gate for this worktree."),
|
|
19919
|
+
startDate: z.number().optional().describe("Planned start timestamp in milliseconds since epoch."),
|
|
19920
|
+
endDate: z.number().optional().describe("Planned end timestamp in milliseconds since epoch."),
|
|
19921
|
+
durationWeeks: z.number().optional().describe("Planned duration in weeks."),
|
|
19922
|
+
confidenceImpact: z.enum(["high", "medium", "low"]).optional().describe("Expected confidence impact if this worktree succeeds."),
|
|
19923
|
+
beliefFocus: z.string().optional().describe("Natural-language focus spanning the target belief neighborhood."),
|
|
19924
|
+
beliefIds: z.array(z.string()).optional().describe("Legacy alias for targetBeliefIds."),
|
|
19925
|
+
beliefs: z.array(z.string()).optional().describe("Legacy alias for targetBeliefIds."),
|
|
19926
|
+
targetBeliefIds: z.array(z.string()).optional().describe("Belief node IDs this worktree is expected to test or update."),
|
|
19927
|
+
targetQuestionIds: z.array(z.string()).optional().describe("Question node IDs this worktree is expected to answer."),
|
|
19928
|
+
keyQuestions: z.array(worktreeKeyQuestionInputSchema).optional().describe("Inline key questions captured as part of the worktree plan."),
|
|
19929
|
+
evidenceSignals: z.array(worktreeEvidenceSignalInputSchema).optional().describe("Evidence signals the worktree needs to collect or validate."),
|
|
19930
|
+
decisionGate: worktreeDecisionGateInputSchema.optional(),
|
|
19931
|
+
goCriteria: z.array(z.string()).optional().describe("Shorthand go criteria used to build decisionGate."),
|
|
19932
|
+
noGoSignals: z.array(z.string()).optional().describe("Shorthand no-go signals used to build decisionGate."),
|
|
19933
|
+
proofArtifacts: z.array(z.unknown()).optional().describe("Expected proof artifacts required to close the worktree."),
|
|
19934
|
+
autoShape: z.boolean().optional().describe("Whether to invoke inquiry auto-shaping during creation."),
|
|
19935
|
+
autoFixPolicy: autoFixPolicyInputSchema.optional(),
|
|
19936
|
+
domainPackId: z.string().optional().describe("Domain pack whose shaping hooks should influence the worktree."),
|
|
19937
|
+
campaign: z.number().optional().describe("Top-level pipeline campaign number."),
|
|
19938
|
+
lane: z.string().optional().describe("Campaign lane for the worktree."),
|
|
19939
|
+
laneOrderInCampaign: z.number().optional().describe("Ordering for this lane within its campaign."),
|
|
19940
|
+
orderInLane: z.number().optional().describe("Position of this worktree inside its lane."),
|
|
19941
|
+
dependsOn: z.array(z.string()).optional().describe("Worktree IDs that must complete before this worktree."),
|
|
19942
|
+
blocks: z.array(z.string()).optional().describe("Worktree IDs blocked by this worktree."),
|
|
19943
|
+
staffingHint: z.string().optional().describe("Suggested staffing or agent allocation note."),
|
|
19944
|
+
lensId: z.string().optional().describe("Lens that scopes this worktree when applicable."),
|
|
19945
|
+
lastReconciledAt: z.number().optional().describe("Timestamp when worktree metadata was last reconciled.")
|
|
19946
|
+
});
|
|
19815
19947
|
var worktreeIdInput = (input) => compactRecord4({
|
|
19816
19948
|
worktreeId: input.worktreeId ?? input.id
|
|
19817
19949
|
});
|
|
@@ -19844,6 +19976,50 @@ var worktreeMetadataInput = (input) => compactRecord4({
|
|
|
19844
19976
|
autoFixPolicy: input.autoFixPolicy,
|
|
19845
19977
|
lastReconciledAt: input.lastReconciledAt
|
|
19846
19978
|
});
|
|
19979
|
+
var worktreeMetadataArgs = z.object({
|
|
19980
|
+
worktreeId: z.string().describe("The worktree to update."),
|
|
19981
|
+
id: z.string().optional().describe("Worktree ID alias."),
|
|
19982
|
+
topicId: z.string().optional().describe("Primary topic scope."),
|
|
19983
|
+
additionalTopicIds: z.array(z.string()).optional().describe("Additional topic scopes associated with this worktree."),
|
|
19984
|
+
status: z.string().optional().describe("Worktree lifecycle status."),
|
|
19985
|
+
campaign: z.number().optional().describe("Top-level pipeline campaign."),
|
|
19986
|
+
lane: z.string().optional().describe("Campaign lane."),
|
|
19987
|
+
laneOrderInCampaign: z.number().optional().describe("Ordering for this lane within its campaign."),
|
|
19988
|
+
orderInLane: z.number().optional().describe("Position of this worktree inside its lane."),
|
|
19989
|
+
gate: z.string().optional().describe("Exit gate for this worktree."),
|
|
19990
|
+
hypothesis: z.string().optional().describe("Testable claim this worktree investigates."),
|
|
19991
|
+
objective: z.string().optional().describe("Reasoning objective for the worktree."),
|
|
19992
|
+
rationale: z.string().optional().describe("Why this worktree is sequenced here."),
|
|
19993
|
+
proofArtifacts: z.array(z.unknown()).optional().describe("Proof artifacts required to close the worktree."),
|
|
19994
|
+
staffingHint: z.string().optional().describe("Suggested staffing or agent allocation note."),
|
|
19995
|
+
blocks: z.array(z.string()).optional().describe("Worktree IDs blocked by this worktree."),
|
|
19996
|
+
dependsOn: z.array(z.string()).optional().describe("Worktree IDs this worktree depends on."),
|
|
19997
|
+
lensId: z.string().optional().describe("Lens that scopes this worktree."),
|
|
19998
|
+
autoFixPolicy: autoFixPolicyInputSchema.optional(),
|
|
19999
|
+
lastReconciledAt: z.number().optional().describe("Timestamp of the last deterministic reconciliation pass.")
|
|
20000
|
+
});
|
|
20001
|
+
var pushArgs = worktreeMetadataArgs.extend({
|
|
20002
|
+
targetContext: z.string().describe("Where to push merged findings."),
|
|
20003
|
+
beliefIds: z.array(z.string()).optional().describe("Optional subset of beliefs to push.")
|
|
20004
|
+
});
|
|
20005
|
+
var openPullRequestArgs = worktreeMetadataArgs.extend({
|
|
20006
|
+
reviewers: z.array(z.string()).optional().describe("User IDs of requested reviewers."),
|
|
20007
|
+
summary: z.string().describe("Summary of findings and why they are ready for review.")
|
|
20008
|
+
});
|
|
20009
|
+
var mergeKeyFindingsInput = (input) => {
|
|
20010
|
+
if (Array.isArray(input.keyFindings)) {
|
|
20011
|
+
return input.keyFindings;
|
|
20012
|
+
}
|
|
20013
|
+
if (Array.isArray(input.outcomes)) {
|
|
20014
|
+
const findings = input.outcomes.filter(
|
|
20015
|
+
(outcome) => typeof outcome === "string" && outcome.trim().length > 0
|
|
20016
|
+
);
|
|
20017
|
+
if (findings.length > 0) {
|
|
20018
|
+
return findings;
|
|
20019
|
+
}
|
|
20020
|
+
}
|
|
20021
|
+
return [input.summary ?? "Merged worktree"];
|
|
20022
|
+
};
|
|
19847
20023
|
var listAllWorktreesInput = (input) => compactRecord4({
|
|
19848
20024
|
status: input.status,
|
|
19849
20025
|
lane: input.lane,
|
|
@@ -19851,6 +20027,16 @@ var listAllWorktreesInput = (input) => compactRecord4({
|
|
|
19851
20027
|
limit: input.limit
|
|
19852
20028
|
});
|
|
19853
20029
|
var worktreesContracts = [
|
|
20030
|
+
surfaceContract({
|
|
20031
|
+
name: "begin_build_session",
|
|
20032
|
+
kind: "mutation",
|
|
20033
|
+
domain: "worktrees",
|
|
20034
|
+
surfaceClass: "platform_internal",
|
|
20035
|
+
path: "/mcp/build-session/begin",
|
|
20036
|
+
sdkNamespace: "worktrees",
|
|
20037
|
+
sdkMethod: "beginBuildSession",
|
|
20038
|
+
summary: "Begin a coding build session for a worktree."
|
|
20039
|
+
}),
|
|
19854
20040
|
surfaceContract({
|
|
19855
20041
|
name: "add_worktree",
|
|
19856
20042
|
kind: "mutation",
|
|
@@ -19867,13 +20053,12 @@ var worktreesContracts = [
|
|
|
19867
20053
|
inputProjection: (input, context) => withCreatedBy(
|
|
19868
20054
|
compactRecord4({
|
|
19869
20055
|
name: input.name ?? input.title,
|
|
19870
|
-
topicId: input.topicId,
|
|
20056
|
+
topicId: input.topicId ?? input.projectId,
|
|
19871
20057
|
worktreeType: input.worktreeType,
|
|
19872
20058
|
objective: input.objective,
|
|
19873
20059
|
gate: input.gate,
|
|
19874
20060
|
hypothesis: input.hypothesis,
|
|
19875
20061
|
rationale: input.rationale,
|
|
19876
|
-
signal: input.signal,
|
|
19877
20062
|
startDate: input.startDate,
|
|
19878
20063
|
endDate: input.endDate,
|
|
19879
20064
|
durationWeeks: input.durationWeeks,
|
|
@@ -19899,12 +20084,12 @@ var worktreesContracts = [
|
|
|
19899
20084
|
staffingHint: input.staffingHint,
|
|
19900
20085
|
domainPackId: input.domainPackId,
|
|
19901
20086
|
lensId: input.lensId,
|
|
19902
|
-
linkedQuestionId: input.linkedQuestionId,
|
|
19903
20087
|
lastReconciledAt: input.lastReconciledAt
|
|
19904
20088
|
}),
|
|
19905
20089
|
context
|
|
19906
20090
|
)
|
|
19907
|
-
}
|
|
20091
|
+
},
|
|
20092
|
+
args: addWorktreeArgs
|
|
19908
20093
|
}),
|
|
19909
20094
|
surfaceContract({
|
|
19910
20095
|
name: "activate_worktree",
|
|
@@ -20016,7 +20201,8 @@ var worktreesContracts = [
|
|
|
20016
20201
|
functionName: "updateMetadata",
|
|
20017
20202
|
kind: "mutation",
|
|
20018
20203
|
inputProjection: worktreeMetadataInput
|
|
20019
|
-
}
|
|
20204
|
+
},
|
|
20205
|
+
args: worktreeMetadataArgs
|
|
20020
20206
|
}),
|
|
20021
20207
|
surfaceContract({
|
|
20022
20208
|
name: "merge",
|
|
@@ -20034,9 +20220,7 @@ var worktreesContracts = [
|
|
|
20034
20220
|
inputProjection: (input, context) => withUserId(
|
|
20035
20221
|
{
|
|
20036
20222
|
...worktreeIdInput(input),
|
|
20037
|
-
keyFindings: input
|
|
20038
|
-
input.summary ?? "Merged worktree"
|
|
20039
|
-
],
|
|
20223
|
+
keyFindings: mergeKeyFindingsInput(input),
|
|
20040
20224
|
decisionsReached: input.decisionsReached ?? [],
|
|
20041
20225
|
nextSteps: input.nextSteps ?? []
|
|
20042
20226
|
},
|
|
@@ -20058,7 +20242,8 @@ var worktreesContracts = [
|
|
|
20058
20242
|
functionName: "updateMetadata",
|
|
20059
20243
|
kind: "mutation",
|
|
20060
20244
|
inputProjection: worktreeMetadataInput
|
|
20061
|
-
}
|
|
20245
|
+
},
|
|
20246
|
+
args: pushArgs
|
|
20062
20247
|
}),
|
|
20063
20248
|
surfaceContract({
|
|
20064
20249
|
name: "open_pull_request",
|
|
@@ -20074,7 +20259,8 @@ var worktreesContracts = [
|
|
|
20074
20259
|
functionName: "updateMetadata",
|
|
20075
20260
|
kind: "mutation",
|
|
20076
20261
|
inputProjection: worktreeMetadataInput
|
|
20077
|
-
}
|
|
20262
|
+
},
|
|
20263
|
+
args: openPullRequestArgs
|
|
20078
20264
|
})
|
|
20079
20265
|
];
|
|
20080
20266
|
|
|
@@ -20178,6 +20364,15 @@ var createEdgeArgs = z.object({
|
|
|
20178
20364
|
topicId: z.string().optional(),
|
|
20179
20365
|
trustedBypassAccessCheck: z.boolean().optional()
|
|
20180
20366
|
});
|
|
20367
|
+
var queryLineageArgs = z.object({
|
|
20368
|
+
nodeId: z.string().describe("Starting node to trace from."),
|
|
20369
|
+
startNode: z.string().optional().describe("Starting node alias accepted by traversal callers."),
|
|
20370
|
+
depth: z.number().optional().describe("Traversal depth alias."),
|
|
20371
|
+
maxDepth: z.number().optional().describe("Maximum traversal depth."),
|
|
20372
|
+
mode: z.string().optional().describe("Traversal mode."),
|
|
20373
|
+
minLayer: z.string().optional().describe("Minimum epistemic layer."),
|
|
20374
|
+
maxLayer: z.string().optional().describe("Maximum epistemic layer.")
|
|
20375
|
+
});
|
|
20181
20376
|
function graphRefNodeId(ref) {
|
|
20182
20377
|
if (ref.kind === "epistemic_node") {
|
|
20183
20378
|
return ref.nodeId;
|
|
@@ -20248,11 +20443,59 @@ var edgesContracts = [
|
|
|
20248
20443
|
minLayer: input.minLayer,
|
|
20249
20444
|
maxLayer: input.maxLayer
|
|
20250
20445
|
})
|
|
20251
|
-
}
|
|
20446
|
+
},
|
|
20447
|
+
args: queryLineageArgs
|
|
20252
20448
|
})
|
|
20253
20449
|
];
|
|
20254
|
-
|
|
20255
|
-
|
|
20450
|
+
var traversalLayerSchema = z.enum([
|
|
20451
|
+
"L4",
|
|
20452
|
+
"L3",
|
|
20453
|
+
"L2",
|
|
20454
|
+
"L1",
|
|
20455
|
+
"ontological",
|
|
20456
|
+
"organizational"
|
|
20457
|
+
]);
|
|
20458
|
+
var traversalModeSchema = z.enum(["low", "medium", "high", "extra_high"]);
|
|
20459
|
+
var lineageAliasArgs = z.object({
|
|
20460
|
+
nodeId: z.string().optional().describe("Starting node to traverse from."),
|
|
20461
|
+
startNode: z.string().optional().describe("Starting node alias for traversal callers."),
|
|
20462
|
+
entityId: z.string().optional().describe("Entity identifier alias for impact tracing."),
|
|
20463
|
+
depth: z.number().optional().describe("Traversal depth alias."),
|
|
20464
|
+
maxDepth: z.number().optional().describe("Maximum traversal depth."),
|
|
20465
|
+
mode: traversalModeSchema.optional().describe("Traversal mode."),
|
|
20466
|
+
minLayer: traversalLayerSchema.optional().describe("Minimum epistemic layer to include."),
|
|
20467
|
+
maxLayer: traversalLayerSchema.optional().describe("Maximum epistemic layer to include.")
|
|
20468
|
+
});
|
|
20469
|
+
var lineageArgs = lineageAliasArgs.extend({
|
|
20470
|
+
nodeId: z.string().describe("Starting node to traverse from.")
|
|
20471
|
+
});
|
|
20472
|
+
var traverseGraphArgs = lineageAliasArgs.extend({
|
|
20473
|
+
startNode: z.string().describe("Node to start traversal from."),
|
|
20474
|
+
direction: z.enum(["up", "down", "both"]).optional().describe("Traversal direction.")
|
|
20475
|
+
});
|
|
20476
|
+
var graphNeighborhoodArgs = z.object({
|
|
20477
|
+
globalId: z.string().optional().describe("Single root global ID."),
|
|
20478
|
+
globalIds: z.array(z.string()).optional().describe("Root global IDs for the neighborhood."),
|
|
20479
|
+
maxDepth: z.number().optional().describe("Maximum traversal depth."),
|
|
20480
|
+
topicId: z.string().optional().describe("Topic scope for edge lookup."),
|
|
20481
|
+
limit: z.number().optional().describe("Maximum edges to return.")
|
|
20482
|
+
});
|
|
20483
|
+
var flagContradictionArgs = z.object({
|
|
20484
|
+
beliefA: z.string().describe("First belief in tension."),
|
|
20485
|
+
beliefB: z.string().describe("Second belief in tension."),
|
|
20486
|
+
topicId: z.string().optional().describe("Topic scope for the contradiction."),
|
|
20487
|
+
description: z.string().optional().describe("Human-readable contradiction."),
|
|
20488
|
+
severity: z.enum(["critical", "high", "medium", "low"]).optional().describe("Contradiction severity."),
|
|
20489
|
+
defeatType: z.string().optional().describe("Defeat type annotation."),
|
|
20490
|
+
supportingInsightIds: z.array(z.string()).optional().describe("Evidence supporting the primary belief."),
|
|
20491
|
+
contradictingInsightIds: z.array(z.string()).optional().describe("Evidence or beliefs contradicting the primary belief.")
|
|
20492
|
+
});
|
|
20493
|
+
var discoverEntityConnectionsArgs = lineageAliasArgs.extend({
|
|
20494
|
+
nodeId: z.string().describe("Epistemic node ID to find entity connections for."),
|
|
20495
|
+
topicId: z.string().optional().describe("Topic scope override."),
|
|
20496
|
+
minScore: z.number().optional().describe("Minimum match score."),
|
|
20497
|
+
limit: z.number().optional().describe("Maximum candidates to return.")
|
|
20498
|
+
});
|
|
20256
20499
|
var contradictionSeverity = (value) => {
|
|
20257
20500
|
switch (value) {
|
|
20258
20501
|
case "critical":
|
|
@@ -20307,7 +20550,8 @@ var graphContracts = [
|
|
|
20307
20550
|
functionName: "getLineage",
|
|
20308
20551
|
kind: "query",
|
|
20309
20552
|
inputProjection: lineageInput
|
|
20310
|
-
}
|
|
20553
|
+
},
|
|
20554
|
+
args: traverseGraphArgs
|
|
20311
20555
|
}),
|
|
20312
20556
|
surfaceContract({
|
|
20313
20557
|
name: "get_graph_neighborhood",
|
|
@@ -20323,7 +20567,8 @@ var graphContracts = [
|
|
|
20323
20567
|
functionName: "getByTopic",
|
|
20324
20568
|
kind: "query",
|
|
20325
20569
|
inputProjection: topicEdgesInput
|
|
20326
|
-
}
|
|
20570
|
+
},
|
|
20571
|
+
args: graphNeighborhoodArgs
|
|
20327
20572
|
}),
|
|
20328
20573
|
surfaceContract({
|
|
20329
20574
|
name: "get_graph_structure_analysis",
|
|
@@ -20372,7 +20617,8 @@ var graphContracts = [
|
|
|
20372
20617
|
functionName: "create",
|
|
20373
20618
|
kind: "mutation",
|
|
20374
20619
|
inputProjection: flagContradictionInput
|
|
20375
|
-
}
|
|
20620
|
+
},
|
|
20621
|
+
args: flagContradictionArgs
|
|
20376
20622
|
}),
|
|
20377
20623
|
surfaceContract({
|
|
20378
20624
|
name: "detect_confirmation_bias",
|
|
@@ -20463,7 +20709,8 @@ var graphContracts = [
|
|
|
20463
20709
|
functionName: "getLineage",
|
|
20464
20710
|
kind: "query",
|
|
20465
20711
|
inputProjection: lineageInput
|
|
20466
|
-
}
|
|
20712
|
+
},
|
|
20713
|
+
args: discoverEntityConnectionsArgs
|
|
20467
20714
|
}),
|
|
20468
20715
|
surfaceContract({
|
|
20469
20716
|
name: "trigger_belief_review",
|
|
@@ -20494,7 +20741,8 @@ var graphContracts = [
|
|
|
20494
20741
|
functionName: "getLineage",
|
|
20495
20742
|
kind: "query",
|
|
20496
20743
|
inputProjection: lineageInput
|
|
20497
|
-
}
|
|
20744
|
+
},
|
|
20745
|
+
args: lineageArgs
|
|
20498
20746
|
})
|
|
20499
20747
|
];
|
|
20500
20748
|
|
|
@@ -20546,8 +20794,16 @@ var contractsContracts = [
|
|
|
20546
20794
|
}
|
|
20547
20795
|
})
|
|
20548
20796
|
];
|
|
20549
|
-
|
|
20550
|
-
|
|
20797
|
+
var auditTrailArgs = z.object({
|
|
20798
|
+
nodeId: z.string().describe("The node to audit."),
|
|
20799
|
+
id: z.string().optional().describe("Node ID alias."),
|
|
20800
|
+
limit: z.number().optional().describe("Maximum entries to return."),
|
|
20801
|
+
depth: z.number().optional().describe("Traversal depth alias."),
|
|
20802
|
+
maxDepth: z.number().optional().describe("Maximum lineage depth."),
|
|
20803
|
+
mode: z.string().optional().describe("Traversal mode."),
|
|
20804
|
+
minLayer: z.string().optional().describe("Minimum epistemic layer."),
|
|
20805
|
+
maxLayer: z.string().optional().describe("Maximum epistemic layer.")
|
|
20806
|
+
});
|
|
20551
20807
|
var judgmentsContracts = [
|
|
20552
20808
|
surfaceContract({
|
|
20553
20809
|
name: "record_judgment",
|
|
@@ -20602,7 +20858,8 @@ var judgmentsContracts = [
|
|
|
20602
20858
|
minLayer: input.minLayer,
|
|
20603
20859
|
maxLayer: input.maxLayer
|
|
20604
20860
|
})
|
|
20605
|
-
}
|
|
20861
|
+
},
|
|
20862
|
+
args: auditTrailArgs
|
|
20606
20863
|
})
|
|
20607
20864
|
];
|
|
20608
20865
|
|
|
@@ -20667,412 +20924,1721 @@ var coordinationContracts = [
|
|
|
20667
20924
|
sdkMethod: "listActiveSessions",
|
|
20668
20925
|
summary: "List active agent sessions.",
|
|
20669
20926
|
convex: {
|
|
20670
|
-
module: "coordination",
|
|
20671
|
-
functionName: "listActiveSessions",
|
|
20672
|
-
kind: "query"
|
|
20927
|
+
module: "coordination",
|
|
20928
|
+
functionName: "listActiveSessions",
|
|
20929
|
+
kind: "query"
|
|
20930
|
+
}
|
|
20931
|
+
}),
|
|
20932
|
+
surfaceContract({
|
|
20933
|
+
name: "send_agent_message",
|
|
20934
|
+
kind: "mutation",
|
|
20935
|
+
domain: "coordination",
|
|
20936
|
+
surfaceClass: "platform_internal",
|
|
20937
|
+
path: "/coordination/messages/send",
|
|
20938
|
+
sdkNamespace: "coordination",
|
|
20939
|
+
sdkMethod: "sendAgentMessage",
|
|
20940
|
+
summary: "Send a directed agent coordination message.",
|
|
20941
|
+
convex: {
|
|
20942
|
+
module: "coordination",
|
|
20943
|
+
functionName: "sendMessage",
|
|
20944
|
+
kind: "mutation",
|
|
20945
|
+
injectSessionId: "fromSessionId",
|
|
20946
|
+
inputProjection: (input) => ({
|
|
20947
|
+
...input,
|
|
20948
|
+
messageType: typeof input.messageType === "string" ? input.messageType : "note"
|
|
20949
|
+
})
|
|
20950
|
+
}
|
|
20951
|
+
}),
|
|
20952
|
+
surfaceContract({
|
|
20953
|
+
name: "broadcast_message",
|
|
20954
|
+
kind: "mutation",
|
|
20955
|
+
domain: "coordination",
|
|
20956
|
+
surfaceClass: "platform_internal",
|
|
20957
|
+
path: "/coordination/messages/broadcast",
|
|
20958
|
+
sdkNamespace: "coordination",
|
|
20959
|
+
sdkMethod: "broadcastMessage",
|
|
20960
|
+
summary: "Broadcast an agent coordination message.",
|
|
20961
|
+
convex: {
|
|
20962
|
+
module: "coordination",
|
|
20963
|
+
functionName: "sendMessage",
|
|
20964
|
+
kind: "mutation",
|
|
20965
|
+
injectSessionId: "fromSessionId",
|
|
20966
|
+
broadcastToAll: true,
|
|
20967
|
+
inputProjection: (input) => ({
|
|
20968
|
+
...input,
|
|
20969
|
+
messageType: typeof input.messageType === "string" ? input.messageType : "note"
|
|
20970
|
+
})
|
|
20971
|
+
}
|
|
20972
|
+
}),
|
|
20973
|
+
surfaceContract({
|
|
20974
|
+
name: "get_agent_inbox",
|
|
20975
|
+
kind: "query",
|
|
20976
|
+
domain: "coordination",
|
|
20977
|
+
surfaceClass: "platform_internal",
|
|
20978
|
+
path: "/coordination/messages/inbox",
|
|
20979
|
+
sdkNamespace: "coordination",
|
|
20980
|
+
sdkMethod: "getAgentInbox",
|
|
20981
|
+
summary: "Read an agent session inbox.",
|
|
20982
|
+
convex: {
|
|
20983
|
+
module: "coordination",
|
|
20984
|
+
functionName: "getInbox",
|
|
20985
|
+
kind: "query",
|
|
20986
|
+
injectSessionId: "sessionId",
|
|
20987
|
+
inputProjection: (input) => compactRecord4({
|
|
20988
|
+
limit: input.limit
|
|
20989
|
+
})
|
|
20990
|
+
}
|
|
20991
|
+
}),
|
|
20992
|
+
surfaceContract({
|
|
20993
|
+
name: "claim_files",
|
|
20994
|
+
kind: "mutation",
|
|
20995
|
+
domain: "coordination",
|
|
20996
|
+
surfaceClass: "platform_internal",
|
|
20997
|
+
path: "/coordination/file-claims",
|
|
20998
|
+
sdkNamespace: "coordination",
|
|
20999
|
+
sdkMethod: "claimFiles",
|
|
21000
|
+
summary: "Claim files for advisory agent coordination.",
|
|
21001
|
+
convex: {
|
|
21002
|
+
module: "coordination",
|
|
21003
|
+
functionName: "claimFiles",
|
|
21004
|
+
kind: "mutation",
|
|
21005
|
+
injectSessionId: "sessionId",
|
|
21006
|
+
inputProjection: (input) => ({
|
|
21007
|
+
touchedFiles: stringArray(input.touchedFiles) ?? stringArray(input.files) ?? stringArray(input.paths) ?? []
|
|
21008
|
+
})
|
|
21009
|
+
}
|
|
21010
|
+
}),
|
|
21011
|
+
surfaceContract({
|
|
21012
|
+
name: "generate_session_handoff",
|
|
21013
|
+
kind: "query",
|
|
21014
|
+
domain: "bootstrap",
|
|
21015
|
+
surfaceClass: "platform_internal",
|
|
21016
|
+
path: "/bootstrap/session-handoff",
|
|
21017
|
+
sdkNamespace: "bootstrap",
|
|
21018
|
+
sdkMethod: "generateSessionHandoff",
|
|
21019
|
+
summary: "Generate a session handoff package.",
|
|
21020
|
+
convex: {
|
|
21021
|
+
module: "worktrees",
|
|
21022
|
+
functionName: "get",
|
|
21023
|
+
kind: "query",
|
|
21024
|
+
inputProjection: (input) => compactRecord4({
|
|
21025
|
+
worktreeId: input.worktreeId ?? input.id
|
|
21026
|
+
})
|
|
21027
|
+
}
|
|
21028
|
+
})
|
|
21029
|
+
];
|
|
21030
|
+
var pipelineSnapshotArgs = z.object({
|
|
21031
|
+
topicId: z.string().describe("Topic scope ID."),
|
|
21032
|
+
status: z.string().optional().describe("Worktree status filter."),
|
|
21033
|
+
lane: z.string().optional().describe("Campaign lane filter."),
|
|
21034
|
+
campaign: z.number().optional().describe("Campaign number filter."),
|
|
21035
|
+
limit: z.number().optional().describe("Maximum worktrees to inspect.")
|
|
21036
|
+
});
|
|
21037
|
+
var pipelineContracts = [
|
|
21038
|
+
surfaceContract({
|
|
21039
|
+
name: "pipeline_snapshot",
|
|
21040
|
+
kind: "query",
|
|
21041
|
+
domain: "worktrees",
|
|
21042
|
+
surfaceClass: "platform_internal",
|
|
21043
|
+
path: "/worktrees/pipeline-snapshot",
|
|
21044
|
+
sdkNamespace: "worktrees",
|
|
21045
|
+
sdkMethod: "pipelineSnapshot",
|
|
21046
|
+
summary: "Summarize worktree pipeline state for a topic.",
|
|
21047
|
+
convex: {
|
|
21048
|
+
module: "worktrees",
|
|
21049
|
+
functionName: "listAll",
|
|
21050
|
+
kind: "query",
|
|
21051
|
+
inputProjection: (input) => compactRecord4({
|
|
21052
|
+
status: input.status,
|
|
21053
|
+
lane: input.lane,
|
|
21054
|
+
campaign: input.campaign,
|
|
21055
|
+
limit: input.limit
|
|
21056
|
+
})
|
|
21057
|
+
},
|
|
21058
|
+
args: pipelineSnapshotArgs
|
|
21059
|
+
}),
|
|
21060
|
+
surfaceContract({
|
|
21061
|
+
name: "seed_belief_lattice",
|
|
21062
|
+
kind: "mutation",
|
|
21063
|
+
domain: "scope",
|
|
21064
|
+
surfaceClass: "platform_internal",
|
|
21065
|
+
path: "/scope/belief-lattice/seed",
|
|
21066
|
+
sdkNamespace: "context",
|
|
21067
|
+
sdkMethod: "seedBeliefLattice",
|
|
21068
|
+
summary: "Seed baseline belief lattice coverage for a topic.",
|
|
21069
|
+
convex: {
|
|
21070
|
+
module: "contextCompiler",
|
|
21071
|
+
functionName: "seedBeliefLattice",
|
|
21072
|
+
kind: "mutation"
|
|
21073
|
+
}
|
|
21074
|
+
}),
|
|
21075
|
+
surfaceContract({
|
|
21076
|
+
name: "get_lattice_coverage",
|
|
21077
|
+
kind: "query",
|
|
21078
|
+
domain: "scope",
|
|
21079
|
+
surfaceClass: "platform_internal",
|
|
21080
|
+
path: "/scope/belief-lattice/coverage",
|
|
21081
|
+
sdkNamespace: "context",
|
|
21082
|
+
sdkMethod: "getLatticeCoverage",
|
|
21083
|
+
summary: "Read belief lattice coverage for a topic.",
|
|
21084
|
+
convex: {
|
|
21085
|
+
module: "contextCompiler",
|
|
21086
|
+
functionName: "getLatticeCoverage",
|
|
21087
|
+
kind: "query"
|
|
21088
|
+
}
|
|
21089
|
+
})
|
|
21090
|
+
];
|
|
21091
|
+
var recordScopeLearningArgs = z.object({
|
|
21092
|
+
topicId: z.string().optional().describe("Topic scope ID"),
|
|
21093
|
+
summary: z.string().describe("Atomic learning statement"),
|
|
21094
|
+
title: z.string().optional().describe("Optional evidence title, such as a commit, doc, or issue."),
|
|
21095
|
+
body: z.string().optional().describe(
|
|
21096
|
+
"Optional rich evidence body. If omitted, body is synthesized from summary and touched paths."
|
|
21097
|
+
),
|
|
21098
|
+
contentType: z.string().optional().describe("Optional evidence body format, such as markdown or text."),
|
|
21099
|
+
sourceKind: z.enum(["commit", "merge", "doc", "issue", "manual"]).optional().describe("Source type for the learning event"),
|
|
21100
|
+
sourceRef: z.string().optional().describe("Optional source reference, such as SHA, PR number, or URL slug."),
|
|
21101
|
+
sourceUrl: z.string().optional().describe("Optional canonical source URL"),
|
|
21102
|
+
touchedPaths: z.array(z.string()).optional().describe("Optional touched file paths for retrieval hints"),
|
|
21103
|
+
tags: z.array(z.string()).optional().describe("Optional tags"),
|
|
21104
|
+
linkedBeliefNodeId: z.string().optional().describe("Optional belief to attach evidence to"),
|
|
21105
|
+
evidenceRelation: z.enum(["supports", "contradicts"]).optional().describe("Relation to linked belief"),
|
|
21106
|
+
confidence: z.number().optional().describe("Optional confidence in [0,1]"),
|
|
21107
|
+
rationale: z.string().optional().describe("Why this learning should enter the reasoning graph"),
|
|
21108
|
+
createQuestionText: z.string().optional().describe("Optional follow-up question text"),
|
|
21109
|
+
createBeliefText: z.string().optional().describe("Optional new belief text"),
|
|
21110
|
+
beliefType: z.string().optional().describe("Optional belief type for createBeliefText"),
|
|
21111
|
+
text: z.string().optional().describe("Canonical learning text alias."),
|
|
21112
|
+
content: z.string().optional().describe("Canonical learning content alias."),
|
|
21113
|
+
kind: z.string().optional().describe("Evidence kind to store."),
|
|
21114
|
+
sourceType: z.string().optional().describe("Evidence source type."),
|
|
21115
|
+
externalSourceType: z.string().optional().describe("External source type alias."),
|
|
21116
|
+
metadata: z.record(z.unknown()).optional().describe("Learning metadata.")
|
|
21117
|
+
});
|
|
21118
|
+
var codeContextArgs = z.object({
|
|
21119
|
+
topicId: z.string().optional().describe("Topic scope."),
|
|
21120
|
+
filePath: z.string().optional().describe("File path anchor."),
|
|
21121
|
+
includeFailures: z.boolean().optional().describe("Whether to include failed attempts."),
|
|
21122
|
+
limit: z.number().optional().describe("Maximum records to return."),
|
|
21123
|
+
status: z.string().optional().describe("Evidence status filter.")
|
|
21124
|
+
});
|
|
21125
|
+
var recordAttemptArgs = z.object({
|
|
21126
|
+
topicId: z.string().optional().describe("Topic scope."),
|
|
21127
|
+
description: z.string().describe("Attempt description."),
|
|
21128
|
+
errorMessage: z.string().optional().describe("Failure or error message."),
|
|
21129
|
+
filePaths: z.array(z.string()).optional().describe("Files involved in the attempt."),
|
|
21130
|
+
filePath: z.string().optional().describe("Single file path alias."),
|
|
21131
|
+
linkedBeliefId: z.string().optional().describe("Linked belief ID."),
|
|
21132
|
+
metadata: z.record(z.unknown()).optional().describe("Attempt metadata."),
|
|
21133
|
+
rationale: z.string().optional().describe("Why this attempt should be recorded."),
|
|
21134
|
+
title: z.string().optional().describe("Attempt evidence title.")
|
|
21135
|
+
});
|
|
21136
|
+
var learningInput = (input, context) => {
|
|
21137
|
+
const sourceKind = input.sourceKind ?? input.externalSourceType;
|
|
21138
|
+
return withUserId(
|
|
21139
|
+
compactRecord4({
|
|
21140
|
+
projectId: input.projectId,
|
|
21141
|
+
topicId: input.topicId,
|
|
21142
|
+
text: input.summary ?? input.text,
|
|
21143
|
+
title: input.title ?? input.summary ?? "Scope learning",
|
|
21144
|
+
content: input.body ?? input.content ?? input.summary,
|
|
21145
|
+
contentType: input.contentType,
|
|
21146
|
+
kind: input.kind ?? "learning",
|
|
21147
|
+
tags: input.tags ?? [],
|
|
21148
|
+
sourceType: input.sourceType,
|
|
21149
|
+
externalSourceType: input.externalSourceType ?? input.sourceKind,
|
|
21150
|
+
sourceUrl: input.sourceUrl,
|
|
21151
|
+
metadata: compactRecord4({
|
|
21152
|
+
...recordValue2(input.metadata),
|
|
21153
|
+
sourceRef: input.sourceRef,
|
|
21154
|
+
sourceKind,
|
|
21155
|
+
touchedPaths: input.touchedPaths,
|
|
21156
|
+
createQuestionText: input.createQuestionText,
|
|
21157
|
+
createBeliefText: input.createBeliefText,
|
|
21158
|
+
beliefType: input.beliefType
|
|
21159
|
+
}),
|
|
21160
|
+
linkedBeliefNodeId: input.linkedBeliefNodeId,
|
|
21161
|
+
evidenceRelation: input.evidenceRelation,
|
|
21162
|
+
confidence: input.confidence,
|
|
21163
|
+
rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
|
|
21164
|
+
trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
|
|
21165
|
+
}),
|
|
21166
|
+
context
|
|
21167
|
+
);
|
|
21168
|
+
};
|
|
21169
|
+
var attemptInput = (input, context) => withUserId(
|
|
21170
|
+
compactRecord4({
|
|
21171
|
+
projectId: input.projectId,
|
|
21172
|
+
topicId: input.topicId,
|
|
21173
|
+
text: input.description,
|
|
21174
|
+
title: input.title ?? input.description,
|
|
21175
|
+
content: input.errorMessage ?? input.description,
|
|
21176
|
+
kind: "code_attempt",
|
|
21177
|
+
tags: ["code_attempt"],
|
|
21178
|
+
metadata: compactRecord4({
|
|
21179
|
+
...recordValue2(input.metadata),
|
|
21180
|
+
filePaths: input.filePaths,
|
|
21181
|
+
filePath: input.filePath,
|
|
21182
|
+
errorMessage: input.errorMessage,
|
|
21183
|
+
linkedBeliefId: input.linkedBeliefId
|
|
21184
|
+
}),
|
|
21185
|
+
rationale: input.rationale ?? input.reasoning ?? input.errorMessage ?? input.description ?? "Recorded implementation attempt",
|
|
21186
|
+
trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
|
|
21187
|
+
}),
|
|
21188
|
+
context
|
|
21189
|
+
);
|
|
21190
|
+
var codingContracts = [
|
|
21191
|
+
surfaceContract({
|
|
21192
|
+
name: "record_scope_learning",
|
|
21193
|
+
kind: "mutation",
|
|
21194
|
+
domain: "scope",
|
|
21195
|
+
surfaceClass: "platform_internal",
|
|
21196
|
+
path: "/scope/learnings",
|
|
21197
|
+
sdkNamespace: "context",
|
|
21198
|
+
sdkMethod: "recordScopeLearning",
|
|
21199
|
+
summary: "Record a scope-level learning to the reasoning graph.",
|
|
21200
|
+
args: recordScopeLearningArgs,
|
|
21201
|
+
input: recordScopeLearningArgs,
|
|
21202
|
+
convex: {
|
|
21203
|
+
module: "evidence",
|
|
21204
|
+
functionName: "create",
|
|
21205
|
+
kind: "mutation",
|
|
21206
|
+
inputProjection: learningInput
|
|
20673
21207
|
}
|
|
20674
21208
|
}),
|
|
20675
21209
|
surfaceContract({
|
|
20676
|
-
name: "
|
|
21210
|
+
name: "manage_write_policy",
|
|
20677
21211
|
kind: "mutation",
|
|
20678
|
-
domain: "
|
|
20679
|
-
surfaceClass: "
|
|
20680
|
-
path: "/
|
|
20681
|
-
sdkNamespace: "
|
|
20682
|
-
sdkMethod: "
|
|
20683
|
-
summary: "
|
|
21212
|
+
domain: "policy",
|
|
21213
|
+
surfaceClass: "tenant_public",
|
|
21214
|
+
path: "/policy/write-policy/manage",
|
|
21215
|
+
sdkNamespace: "policy",
|
|
21216
|
+
sdkMethod: "manageWritePolicy",
|
|
21217
|
+
summary: "Manage MCP write policy rules.",
|
|
20684
21218
|
convex: {
|
|
20685
|
-
module: "
|
|
20686
|
-
functionName: "
|
|
21219
|
+
module: "evidence",
|
|
21220
|
+
functionName: "create",
|
|
20687
21221
|
kind: "mutation",
|
|
20688
|
-
|
|
20689
|
-
|
|
20690
|
-
|
|
20691
|
-
|
|
20692
|
-
|
|
21222
|
+
inputProjection: (input, context) => learningInput(
|
|
21223
|
+
{
|
|
21224
|
+
...input,
|
|
21225
|
+
summary: input.summary ?? `Write policy ${String(input.action ?? "update")}`,
|
|
21226
|
+
sourceKind: "write_policy"
|
|
21227
|
+
},
|
|
21228
|
+
context
|
|
21229
|
+
)
|
|
20693
21230
|
}
|
|
20694
21231
|
}),
|
|
20695
21232
|
surfaceContract({
|
|
20696
|
-
name: "
|
|
20697
|
-
kind: "
|
|
20698
|
-
domain: "
|
|
21233
|
+
name: "get_code_context",
|
|
21234
|
+
kind: "query",
|
|
21235
|
+
domain: "coding",
|
|
20699
21236
|
surfaceClass: "platform_internal",
|
|
20700
|
-
path: "/
|
|
20701
|
-
sdkNamespace: "
|
|
20702
|
-
sdkMethod: "
|
|
20703
|
-
summary: "
|
|
21237
|
+
path: "/coding/context",
|
|
21238
|
+
sdkNamespace: "coding",
|
|
21239
|
+
sdkMethod: "getCodeContext",
|
|
21240
|
+
summary: "Read code context for graph-linked files.",
|
|
20704
21241
|
convex: {
|
|
20705
|
-
module: "
|
|
20706
|
-
functionName: "
|
|
20707
|
-
kind: "
|
|
20708
|
-
|
|
20709
|
-
|
|
20710
|
-
|
|
20711
|
-
|
|
20712
|
-
|
|
21242
|
+
module: "evidence",
|
|
21243
|
+
functionName: "getByTopic",
|
|
21244
|
+
kind: "query",
|
|
21245
|
+
inputProjection: (input) => compactRecord4({
|
|
21246
|
+
topicId: input.topicId,
|
|
21247
|
+
limit: input.limit,
|
|
21248
|
+
status: input.status,
|
|
21249
|
+
userId: input.userId
|
|
20713
21250
|
})
|
|
20714
|
-
}
|
|
21251
|
+
},
|
|
21252
|
+
args: codeContextArgs
|
|
20715
21253
|
}),
|
|
20716
21254
|
surfaceContract({
|
|
20717
|
-
name: "
|
|
21255
|
+
name: "get_change_history",
|
|
20718
21256
|
kind: "query",
|
|
20719
|
-
domain: "
|
|
21257
|
+
domain: "coding",
|
|
20720
21258
|
surfaceClass: "platform_internal",
|
|
20721
|
-
path: "/
|
|
20722
|
-
sdkNamespace: "
|
|
20723
|
-
sdkMethod: "
|
|
20724
|
-
summary: "Read
|
|
21259
|
+
path: "/coding/change-history",
|
|
21260
|
+
sdkNamespace: "coding",
|
|
21261
|
+
sdkMethod: "getChangeHistory",
|
|
21262
|
+
summary: "Read recorded code change attempts.",
|
|
20725
21263
|
convex: {
|
|
20726
|
-
module: "
|
|
20727
|
-
functionName: "
|
|
21264
|
+
module: "evidence",
|
|
21265
|
+
functionName: "getByTopic",
|
|
20728
21266
|
kind: "query",
|
|
20729
|
-
injectSessionId: "sessionId",
|
|
20730
21267
|
inputProjection: (input) => compactRecord4({
|
|
20731
|
-
|
|
21268
|
+
topicId: input.topicId,
|
|
21269
|
+
limit: input.limit,
|
|
21270
|
+
status: input.status,
|
|
21271
|
+
userId: input.userId
|
|
20732
21272
|
})
|
|
20733
21273
|
}
|
|
20734
21274
|
}),
|
|
20735
21275
|
surfaceContract({
|
|
20736
|
-
name: "
|
|
21276
|
+
name: "record_attempt",
|
|
20737
21277
|
kind: "mutation",
|
|
20738
|
-
domain: "
|
|
21278
|
+
domain: "coding",
|
|
20739
21279
|
surfaceClass: "platform_internal",
|
|
20740
|
-
path: "/
|
|
20741
|
-
sdkNamespace: "
|
|
20742
|
-
sdkMethod: "
|
|
20743
|
-
summary: "
|
|
21280
|
+
path: "/coding/attempts",
|
|
21281
|
+
sdkNamespace: "coding",
|
|
21282
|
+
sdkMethod: "recordAttempt",
|
|
21283
|
+
summary: "Record a code attempt for failure learning.",
|
|
20744
21284
|
convex: {
|
|
20745
|
-
module: "
|
|
20746
|
-
functionName: "
|
|
21285
|
+
module: "evidence",
|
|
21286
|
+
functionName: "create",
|
|
20747
21287
|
kind: "mutation",
|
|
20748
|
-
|
|
20749
|
-
|
|
20750
|
-
|
|
20751
|
-
})
|
|
20752
|
-
}
|
|
21288
|
+
inputProjection: attemptInput
|
|
21289
|
+
},
|
|
21290
|
+
args: recordAttemptArgs
|
|
20753
21291
|
}),
|
|
20754
21292
|
surfaceContract({
|
|
20755
|
-
name: "
|
|
21293
|
+
name: "get_failure_log",
|
|
20756
21294
|
kind: "query",
|
|
20757
|
-
domain: "
|
|
21295
|
+
domain: "coding",
|
|
20758
21296
|
surfaceClass: "platform_internal",
|
|
20759
|
-
path: "/
|
|
20760
|
-
sdkNamespace: "
|
|
20761
|
-
sdkMethod: "
|
|
20762
|
-
summary: "
|
|
21297
|
+
path: "/coding/failure-log",
|
|
21298
|
+
sdkNamespace: "coding",
|
|
21299
|
+
sdkMethod: "getFailureLog",
|
|
21300
|
+
summary: "Read code failure log entries.",
|
|
20763
21301
|
convex: {
|
|
20764
|
-
module: "
|
|
20765
|
-
functionName: "
|
|
21302
|
+
module: "evidence",
|
|
21303
|
+
functionName: "getByTopic",
|
|
20766
21304
|
kind: "query",
|
|
20767
21305
|
inputProjection: (input) => compactRecord4({
|
|
20768
|
-
|
|
21306
|
+
topicId: input.topicId ?? input.query,
|
|
21307
|
+
limit: input.limit,
|
|
21308
|
+
status: input.status,
|
|
21309
|
+
userId: input.userId
|
|
21310
|
+
})
|
|
21311
|
+
}
|
|
21312
|
+
})
|
|
21313
|
+
];
|
|
21314
|
+
|
|
21315
|
+
// ../contracts/src/function-registry/legacy.ts
|
|
21316
|
+
var legacyContracts = [
|
|
21317
|
+
surfaceContract({
|
|
21318
|
+
name: "discover",
|
|
21319
|
+
kind: "query",
|
|
21320
|
+
domain: "context",
|
|
21321
|
+
surfaceClass: "legacy_compat",
|
|
21322
|
+
replacedBy: "compile_context",
|
|
21323
|
+
path: "/context/discover",
|
|
21324
|
+
sdkNamespace: "context",
|
|
21325
|
+
sdkMethod: "discover",
|
|
21326
|
+
summary: "Discover relevant topic context.",
|
|
21327
|
+
convex: {
|
|
21328
|
+
module: "contextCompiler",
|
|
21329
|
+
functionName: "compile",
|
|
21330
|
+
kind: "query",
|
|
21331
|
+
inputProjection: (input) => ({
|
|
21332
|
+
...input,
|
|
21333
|
+
query: input.query ?? input.prompt ?? input.topicHint ?? "discover"
|
|
20769
21334
|
})
|
|
20770
21335
|
}
|
|
20771
21336
|
})
|
|
20772
21337
|
];
|
|
20773
21338
|
|
|
20774
|
-
// ../contracts/src/function-registry/
|
|
20775
|
-
var
|
|
20776
|
-
|
|
20777
|
-
|
|
20778
|
-
|
|
20779
|
-
|
|
20780
|
-
|
|
20781
|
-
|
|
20782
|
-
|
|
20783
|
-
|
|
20784
|
-
|
|
20785
|
-
|
|
20786
|
-
|
|
20787
|
-
|
|
20788
|
-
|
|
20789
|
-
|
|
20790
|
-
|
|
20791
|
-
|
|
20792
|
-
|
|
20793
|
-
|
|
20794
|
-
|
|
21339
|
+
// ../contracts/src/function-registry/index.ts
|
|
21340
|
+
var ALL_FUNCTION_CONTRACTS = [
|
|
21341
|
+
...contextContracts,
|
|
21342
|
+
...identityContracts,
|
|
21343
|
+
...beliefsContracts,
|
|
21344
|
+
...evidenceContracts,
|
|
21345
|
+
...questionsContracts,
|
|
21346
|
+
...topicsContracts,
|
|
21347
|
+
...lensesContracts,
|
|
21348
|
+
...ontologiesContracts,
|
|
21349
|
+
...worktreesContracts,
|
|
21350
|
+
...tasksContracts,
|
|
21351
|
+
...edgesContracts,
|
|
21352
|
+
...graphContracts,
|
|
21353
|
+
...contractsContracts,
|
|
21354
|
+
...judgmentsContracts,
|
|
21355
|
+
...coordinationContracts,
|
|
21356
|
+
...pipelineContracts,
|
|
21357
|
+
...codingContracts,
|
|
21358
|
+
...legacyContracts
|
|
21359
|
+
];
|
|
21360
|
+
assertSurfaceCoverage(ALL_FUNCTION_CONTRACTS);
|
|
21361
|
+
var FUNCTION_SURFACE_CONTRACTS = ALL_FUNCTION_CONTRACTS;
|
|
21362
|
+
new Map(
|
|
21363
|
+
ALL_FUNCTION_CONTRACTS.map((contract) => [contract.name, contract])
|
|
21364
|
+
);
|
|
21365
|
+
|
|
21366
|
+
// ../contracts/src/tenant-bootstrap-seed.contract.ts
|
|
21367
|
+
function isCopyableSeedRequirement(entry) {
|
|
21368
|
+
return (entry.copyMode === "template_global" || entry.copyMode === "template_tenant_rewrite" || entry.copyMode === "template_reference_remap") && Boolean(entry.scope) && Array.isArray(entry.uniqueKey) && entry.uniqueKey.length > 0;
|
|
21369
|
+
}
|
|
21370
|
+
var TENANT_BOOTSTRAP_TABLE_REQUIREMENTS = [
|
|
21371
|
+
{
|
|
21372
|
+
component: "kernel",
|
|
21373
|
+
table: "agentMessages",
|
|
21374
|
+
prepopulation: "runtime_data",
|
|
21375
|
+
copyMode: "none",
|
|
21376
|
+
description: "Agent coordination messages are session data, not template data."
|
|
21377
|
+
},
|
|
21378
|
+
{
|
|
21379
|
+
component: "kernel",
|
|
21380
|
+
table: "agentSessions",
|
|
21381
|
+
prepopulation: "runtime_data",
|
|
21382
|
+
copyMode: "none",
|
|
21383
|
+
description: "Agent coordination sessions are created by active clients."
|
|
21384
|
+
},
|
|
21385
|
+
{
|
|
21386
|
+
component: "kernel",
|
|
21387
|
+
table: "autofixJobs",
|
|
21388
|
+
prepopulation: "runtime_queue",
|
|
21389
|
+
copyMode: "none",
|
|
21390
|
+
description: "Autofix work items are runtime queue rows."
|
|
21391
|
+
},
|
|
21392
|
+
{
|
|
21393
|
+
component: "kernel",
|
|
21394
|
+
table: "backgroundJobRuns",
|
|
21395
|
+
prepopulation: "runtime_log",
|
|
21396
|
+
copyMode: "none",
|
|
21397
|
+
description: "Background job executions are runtime logs."
|
|
21398
|
+
},
|
|
21399
|
+
{
|
|
21400
|
+
component: "kernel",
|
|
21401
|
+
table: "backgroundJobSettings",
|
|
21402
|
+
prepopulation: "required_template",
|
|
21403
|
+
copyMode: "template_global",
|
|
21404
|
+
scope: "global",
|
|
21405
|
+
uniqueKey: ["jobKey"],
|
|
21406
|
+
description: "Default job enablement settings must come from the K template."
|
|
21407
|
+
},
|
|
21408
|
+
{
|
|
21409
|
+
component: "kernel",
|
|
21410
|
+
table: "beliefConfidence",
|
|
21411
|
+
prepopulation: "runtime_data",
|
|
21412
|
+
copyMode: "none",
|
|
21413
|
+
description: "Belief confidence rows are created with tenant graph facts."
|
|
21414
|
+
},
|
|
21415
|
+
{
|
|
21416
|
+
component: "kernel",
|
|
21417
|
+
table: "beliefEvidenceLinks",
|
|
21418
|
+
prepopulation: "runtime_data",
|
|
21419
|
+
copyMode: "none",
|
|
21420
|
+
description: "Belief-to-evidence links are tenant graph data."
|
|
21421
|
+
},
|
|
21422
|
+
{
|
|
21423
|
+
component: "kernel",
|
|
21424
|
+
table: "beliefHistory",
|
|
21425
|
+
prepopulation: "runtime_data",
|
|
21426
|
+
copyMode: "none",
|
|
21427
|
+
description: "Belief history is append-only tenant graph data."
|
|
21428
|
+
},
|
|
21429
|
+
{
|
|
21430
|
+
component: "kernel",
|
|
21431
|
+
table: "beliefScenarios",
|
|
21432
|
+
prepopulation: "runtime_data",
|
|
21433
|
+
copyMode: "none",
|
|
21434
|
+
description: "Scenario rows are tenant-authored reasoning data."
|
|
21435
|
+
},
|
|
21436
|
+
{
|
|
21437
|
+
component: "kernel",
|
|
21438
|
+
table: "beliefVotes",
|
|
21439
|
+
prepopulation: "runtime_data",
|
|
21440
|
+
copyMode: "none",
|
|
21441
|
+
description: "Decision belief votes are tenant-authored data."
|
|
21442
|
+
},
|
|
21443
|
+
{
|
|
21444
|
+
component: "kernel",
|
|
21445
|
+
table: "calibrationScores",
|
|
21446
|
+
prepopulation: "runtime_derived",
|
|
21447
|
+
copyMode: "none",
|
|
21448
|
+
description: "Calibration scores are computed from tenant outcomes."
|
|
21449
|
+
},
|
|
21450
|
+
{
|
|
21451
|
+
component: "kernel",
|
|
21452
|
+
table: "contractEvaluations",
|
|
21453
|
+
prepopulation: "runtime_log",
|
|
21454
|
+
copyMode: "none",
|
|
21455
|
+
description: "Contract evaluation rows are runtime computation logs."
|
|
21456
|
+
},
|
|
21457
|
+
{
|
|
21458
|
+
component: "kernel",
|
|
21459
|
+
table: "contradictions",
|
|
21460
|
+
prepopulation: "runtime_data",
|
|
21461
|
+
copyMode: "none",
|
|
21462
|
+
description: "Contradictions are tenant graph facts."
|
|
21463
|
+
},
|
|
21464
|
+
{
|
|
21465
|
+
component: "kernel",
|
|
21466
|
+
table: "crossProjectConnections",
|
|
21467
|
+
prepopulation: "runtime_data",
|
|
21468
|
+
copyMode: "none",
|
|
21469
|
+
description: "Cross-topic connections are tenant graph facts."
|
|
21470
|
+
},
|
|
21471
|
+
{
|
|
21472
|
+
component: "kernel",
|
|
21473
|
+
table: "decisionComputedSummaries",
|
|
21474
|
+
prepopulation: "runtime_derived",
|
|
21475
|
+
copyMode: "none",
|
|
21476
|
+
description: "Decision summaries are derived tenant outputs."
|
|
21477
|
+
},
|
|
21478
|
+
{
|
|
21479
|
+
component: "kernel",
|
|
21480
|
+
table: "decisionEvents",
|
|
21481
|
+
prepopulation: "runtime_data",
|
|
21482
|
+
copyMode: "none",
|
|
21483
|
+
description: "Decision events are lifecycle data."
|
|
21484
|
+
},
|
|
21485
|
+
{
|
|
21486
|
+
component: "kernel",
|
|
21487
|
+
table: "decisionParticipants",
|
|
21488
|
+
prepopulation: "runtime_data",
|
|
21489
|
+
copyMode: "none",
|
|
21490
|
+
description: "Decision participants are tenant-selected actors."
|
|
21491
|
+
},
|
|
21492
|
+
{
|
|
21493
|
+
component: "kernel",
|
|
21494
|
+
table: "decisionRiskLedger",
|
|
21495
|
+
prepopulation: "runtime_data",
|
|
21496
|
+
copyMode: "none",
|
|
21497
|
+
description: "Decision risk rows are tenant decision data."
|
|
21498
|
+
},
|
|
21499
|
+
{
|
|
21500
|
+
component: "kernel",
|
|
21501
|
+
table: "decisionSnapshots",
|
|
21502
|
+
prepopulation: "runtime_derived",
|
|
21503
|
+
copyMode: "none",
|
|
21504
|
+
description: "Decision snapshots are derived from tenant state."
|
|
21505
|
+
},
|
|
21506
|
+
{
|
|
21507
|
+
component: "kernel",
|
|
21508
|
+
table: "deliberationContributions",
|
|
21509
|
+
prepopulation: "runtime_data",
|
|
21510
|
+
copyMode: "none",
|
|
21511
|
+
description: "Deliberation contributions are tenant-authored data."
|
|
21512
|
+
},
|
|
21513
|
+
{
|
|
21514
|
+
component: "kernel",
|
|
21515
|
+
table: "deliberationSessions",
|
|
21516
|
+
prepopulation: "runtime_data",
|
|
21517
|
+
copyMode: "none",
|
|
21518
|
+
description: "Deliberation sessions are created by tenant workflows."
|
|
21519
|
+
},
|
|
21520
|
+
{
|
|
21521
|
+
component: "kernel",
|
|
21522
|
+
table: "epistemicAudit",
|
|
21523
|
+
prepopulation: "runtime_log",
|
|
21524
|
+
copyMode: "none",
|
|
21525
|
+
description: "Epistemic audit rows are append-only runtime audit data."
|
|
21526
|
+
},
|
|
21527
|
+
{
|
|
21528
|
+
component: "kernel",
|
|
21529
|
+
table: "epistemicContracts",
|
|
21530
|
+
prepopulation: "runtime_data",
|
|
21531
|
+
copyMode: "none",
|
|
21532
|
+
description: "Epistemic contracts are tenant-authored governance data."
|
|
21533
|
+
},
|
|
21534
|
+
{
|
|
21535
|
+
component: "kernel",
|
|
21536
|
+
table: "epistemicEdges",
|
|
21537
|
+
prepopulation: "runtime_data",
|
|
21538
|
+
copyMode: "none",
|
|
21539
|
+
description: "Edges are tenant reasoning graph data."
|
|
21540
|
+
},
|
|
21541
|
+
{
|
|
21542
|
+
component: "kernel",
|
|
21543
|
+
table: "epistemicNodeEmbeddings",
|
|
21544
|
+
prepopulation: "runtime_derived",
|
|
21545
|
+
copyMode: "none",
|
|
21546
|
+
description: "Embeddings are derived from tenant graph nodes."
|
|
21547
|
+
},
|
|
21548
|
+
{
|
|
21549
|
+
component: "kernel",
|
|
21550
|
+
table: "epistemicNodes",
|
|
21551
|
+
prepopulation: "runtime_data",
|
|
21552
|
+
copyMode: "none",
|
|
21553
|
+
description: "Nodes are tenant reasoning graph data."
|
|
21554
|
+
},
|
|
21555
|
+
{
|
|
21556
|
+
component: "kernel",
|
|
21557
|
+
table: "graphAnalysisCache",
|
|
21558
|
+
prepopulation: "runtime_derived",
|
|
21559
|
+
copyMode: "none",
|
|
21560
|
+
description: "Graph analysis cache rows are derived from tenant graph state."
|
|
21561
|
+
},
|
|
21562
|
+
{
|
|
21563
|
+
component: "kernel",
|
|
21564
|
+
table: "graphAnalysisResults",
|
|
21565
|
+
prepopulation: "runtime_derived",
|
|
21566
|
+
copyMode: "none",
|
|
21567
|
+
description: "Graph analysis result rows are derived tenant outputs."
|
|
21568
|
+
},
|
|
21569
|
+
{
|
|
21570
|
+
component: "kernel",
|
|
21571
|
+
table: "graphSuggestions",
|
|
21572
|
+
prepopulation: "runtime_derived",
|
|
21573
|
+
copyMode: "none",
|
|
21574
|
+
description: "Graph suggestions are derived recommendations."
|
|
21575
|
+
},
|
|
21576
|
+
{
|
|
21577
|
+
component: "kernel",
|
|
21578
|
+
table: "harnessReplays",
|
|
21579
|
+
prepopulation: "runtime_log",
|
|
21580
|
+
copyMode: "none",
|
|
21581
|
+
description: "Harness replay rows are runtime verification logs."
|
|
21582
|
+
},
|
|
21583
|
+
{
|
|
21584
|
+
component: "kernel",
|
|
21585
|
+
table: "harnessRuns",
|
|
21586
|
+
prepopulation: "runtime_log",
|
|
21587
|
+
copyMode: "none",
|
|
21588
|
+
description: "Harness run rows are runtime verification logs."
|
|
21589
|
+
},
|
|
21590
|
+
{
|
|
21591
|
+
component: "kernel",
|
|
21592
|
+
table: "idempotencyTokens",
|
|
21593
|
+
prepopulation: "runtime_log",
|
|
21594
|
+
copyMode: "none",
|
|
21595
|
+
description: "Idempotency tokens are request-scoped runtime guards."
|
|
21596
|
+
},
|
|
21597
|
+
{
|
|
21598
|
+
component: "kernel",
|
|
21599
|
+
table: "lenses",
|
|
21600
|
+
prepopulation: "optional_template",
|
|
21601
|
+
copyMode: "none",
|
|
21602
|
+
description: "Reusable lens templates may live in K templates, but workspace-specific copies are not required for core SDK boot."
|
|
21603
|
+
},
|
|
21604
|
+
{
|
|
21605
|
+
component: "kernel",
|
|
21606
|
+
table: "lensTopicBindings",
|
|
21607
|
+
prepopulation: "runtime_data",
|
|
21608
|
+
copyMode: "none",
|
|
21609
|
+
description: "Lens bindings attach runtime topics to runtime/workspace lenses."
|
|
21610
|
+
},
|
|
21611
|
+
{
|
|
21612
|
+
component: "kernel",
|
|
21613
|
+
table: "neo4jSyncQueue",
|
|
21614
|
+
prepopulation: "runtime_queue",
|
|
21615
|
+
copyMode: "none",
|
|
21616
|
+
description: "Neo4j sync queue rows are runtime work items."
|
|
21617
|
+
},
|
|
21618
|
+
{
|
|
21619
|
+
component: "kernel",
|
|
21620
|
+
table: "ontologyDefinitions",
|
|
21621
|
+
prepopulation: "required_template",
|
|
21622
|
+
copyMode: "template_global",
|
|
21623
|
+
scope: "global",
|
|
21624
|
+
uniqueKey: ["ontologyKey"],
|
|
21625
|
+
description: "Platform ontology definitions power taxonomy reads and effective ontology resolution."
|
|
21626
|
+
},
|
|
21627
|
+
{
|
|
21628
|
+
component: "kernel",
|
|
21629
|
+
table: "ontologyVersions",
|
|
21630
|
+
prepopulation: "required_template",
|
|
21631
|
+
copyMode: "template_reference_remap",
|
|
21632
|
+
scope: "global",
|
|
21633
|
+
uniqueKey: ["ontologyKey", "version"],
|
|
21634
|
+
dependsOn: ["ontologyDefinitions"],
|
|
21635
|
+
description: "Ontology versions must be copied with ontologyDefinition ID remapping."
|
|
21636
|
+
},
|
|
21637
|
+
{
|
|
21638
|
+
component: "kernel",
|
|
21639
|
+
table: "platformAgentRunPolicyDecisions",
|
|
21640
|
+
prepopulation: "runtime_log",
|
|
21641
|
+
copyMode: "none",
|
|
21642
|
+
description: "Agent-run policy decisions are audit logs."
|
|
21643
|
+
},
|
|
21644
|
+
{
|
|
21645
|
+
component: "kernel",
|
|
21646
|
+
table: "platformAgentRunPromptResolutions",
|
|
21647
|
+
prepopulation: "runtime_log",
|
|
21648
|
+
copyMode: "none",
|
|
21649
|
+
description: "Agent-run prompt resolution rows are runtime logs."
|
|
21650
|
+
},
|
|
21651
|
+
{
|
|
21652
|
+
component: "kernel",
|
|
21653
|
+
table: "platformAgentRuns",
|
|
21654
|
+
prepopulation: "runtime_log",
|
|
21655
|
+
copyMode: "none",
|
|
21656
|
+
description: "Agent runs are runtime execution records."
|
|
21657
|
+
},
|
|
21658
|
+
{
|
|
21659
|
+
component: "kernel",
|
|
21660
|
+
table: "platformAgentRunToolCalls",
|
|
21661
|
+
prepopulation: "runtime_log",
|
|
21662
|
+
copyMode: "none",
|
|
21663
|
+
description: "Agent-run tool calls are runtime execution records."
|
|
21664
|
+
},
|
|
21665
|
+
{
|
|
21666
|
+
component: "kernel",
|
|
21667
|
+
table: "platformHarnessShadowAudit",
|
|
21668
|
+
prepopulation: "runtime_log",
|
|
21669
|
+
copyMode: "none",
|
|
21670
|
+
description: "Harness shadow audit rows are runtime audit records."
|
|
21671
|
+
},
|
|
21672
|
+
{
|
|
21673
|
+
component: "kernel",
|
|
21674
|
+
table: "publicationRules",
|
|
21675
|
+
prepopulation: "required_template",
|
|
21676
|
+
copyMode: "template_tenant_rewrite",
|
|
21677
|
+
scope: "tenant",
|
|
21678
|
+
uniqueKey: ["tenantId", "workspaceId", "name"],
|
|
21679
|
+
description: "Default publication policy rules are rewritten into each tenant."
|
|
21680
|
+
},
|
|
21681
|
+
{
|
|
21682
|
+
component: "kernel",
|
|
21683
|
+
table: "questionEvidenceLinks",
|
|
21684
|
+
prepopulation: "runtime_data",
|
|
21685
|
+
copyMode: "none",
|
|
21686
|
+
description: "Question-to-evidence links are tenant graph data."
|
|
21687
|
+
},
|
|
21688
|
+
{
|
|
21689
|
+
component: "kernel",
|
|
21690
|
+
table: "researchJobs",
|
|
21691
|
+
prepopulation: "runtime_queue",
|
|
21692
|
+
copyMode: "none",
|
|
21693
|
+
description: "Research job rows are runtime queue items."
|
|
21694
|
+
},
|
|
21695
|
+
{
|
|
21696
|
+
component: "kernel",
|
|
21697
|
+
table: "schemaEnumConfig",
|
|
21698
|
+
prepopulation: "required_template",
|
|
21699
|
+
copyMode: "template_global",
|
|
21700
|
+
scope: "global",
|
|
21701
|
+
uniqueKey: ["category", "value"],
|
|
21702
|
+
description: "Runtime-extensible enum defaults required by SDK graph APIs."
|
|
21703
|
+
},
|
|
21704
|
+
{
|
|
21705
|
+
component: "kernel",
|
|
21706
|
+
table: "stakeholderGroups",
|
|
21707
|
+
prepopulation: "runtime_data",
|
|
21708
|
+
copyMode: "none",
|
|
21709
|
+
description: "Stakeholder groups are tenant decision data."
|
|
21710
|
+
},
|
|
21711
|
+
{
|
|
21712
|
+
component: "kernel",
|
|
21713
|
+
table: "systemLogs",
|
|
21714
|
+
prepopulation: "runtime_log",
|
|
21715
|
+
copyMode: "none",
|
|
21716
|
+
description: "System logs are runtime telemetry."
|
|
21717
|
+
},
|
|
21718
|
+
{
|
|
21719
|
+
component: "kernel",
|
|
21720
|
+
table: "tasks",
|
|
21721
|
+
prepopulation: "runtime_data",
|
|
21722
|
+
copyMode: "none",
|
|
21723
|
+
description: "Tasks are tenant-authored work items."
|
|
21724
|
+
},
|
|
21725
|
+
{
|
|
21726
|
+
component: "kernel",
|
|
21727
|
+
table: "topics",
|
|
21728
|
+
prepopulation: "runtime_bootstrap",
|
|
21729
|
+
copyMode: "none",
|
|
21730
|
+
description: "Default topics are created by tenant provisioning, not copied from templates."
|
|
21731
|
+
},
|
|
21732
|
+
{
|
|
21733
|
+
component: "kernel",
|
|
21734
|
+
table: "workflowDefinitions",
|
|
21735
|
+
prepopulation: "optional_template",
|
|
21736
|
+
copyMode: "none",
|
|
21737
|
+
description: "Table-driven workflow definitions can be template data after the workflow engine leaves legacy mode."
|
|
21738
|
+
},
|
|
21739
|
+
{
|
|
21740
|
+
component: "kernel",
|
|
21741
|
+
table: "workflowPullRequests",
|
|
21742
|
+
prepopulation: "runtime_data",
|
|
21743
|
+
copyMode: "none",
|
|
21744
|
+
description: "Workflow pull requests are tenant workflow data."
|
|
21745
|
+
},
|
|
21746
|
+
{
|
|
21747
|
+
component: "kernel",
|
|
21748
|
+
table: "workflowStages",
|
|
21749
|
+
prepopulation: "optional_template",
|
|
21750
|
+
copyMode: "none",
|
|
21751
|
+
dependsOn: ["workflowDefinitions"],
|
|
21752
|
+
description: "Workflow stages can be template data after workflowDefinitions are enabled for bootstrap copying."
|
|
21753
|
+
},
|
|
21754
|
+
{
|
|
21755
|
+
component: "kernel",
|
|
21756
|
+
table: "worktreeBeliefCluster",
|
|
21757
|
+
prepopulation: "runtime_data",
|
|
21758
|
+
copyMode: "none",
|
|
21759
|
+
description: "Worktree cluster rows link runtime worktrees to runtime beliefs."
|
|
21760
|
+
},
|
|
21761
|
+
{
|
|
21762
|
+
component: "kernel",
|
|
21763
|
+
table: "worktrees",
|
|
21764
|
+
prepopulation: "runtime_data",
|
|
21765
|
+
copyMode: "none",
|
|
21766
|
+
description: "Worktrees are tenant/runtime planning data."
|
|
21767
|
+
},
|
|
21768
|
+
{
|
|
21769
|
+
component: "identity",
|
|
21770
|
+
table: "agents",
|
|
21771
|
+
prepopulation: "runtime_bootstrap",
|
|
21772
|
+
copyMode: "none",
|
|
21773
|
+
description: "Service agents are provisioned per tenant or service, not copied."
|
|
21774
|
+
},
|
|
21775
|
+
{
|
|
21776
|
+
component: "identity",
|
|
21777
|
+
table: "mcpWritePolicy",
|
|
21778
|
+
prepopulation: "required_template",
|
|
21779
|
+
copyMode: "template_global",
|
|
21780
|
+
scope: "global",
|
|
21781
|
+
uniqueKey: ["topicId", "role", "toolCategory"],
|
|
21782
|
+
description: "Global write policy defaults govern service and interactive MCP writes."
|
|
21783
|
+
},
|
|
21784
|
+
{
|
|
21785
|
+
component: "identity",
|
|
21786
|
+
table: "modelCallLogs",
|
|
21787
|
+
prepopulation: "runtime_log",
|
|
21788
|
+
copyMode: "none",
|
|
21789
|
+
description: "Model call logs are runtime telemetry."
|
|
21790
|
+
},
|
|
21791
|
+
{
|
|
21792
|
+
component: "identity",
|
|
21793
|
+
table: "modelFunctionSlots",
|
|
21794
|
+
prepopulation: "required_template",
|
|
21795
|
+
copyMode: "template_global",
|
|
21796
|
+
scope: "global",
|
|
21797
|
+
uniqueKey: ["slot"],
|
|
21798
|
+
description: "Function-to-model slots are required by model runtime resolution."
|
|
21799
|
+
},
|
|
21800
|
+
{
|
|
21801
|
+
component: "identity",
|
|
21802
|
+
table: "modelRegistry",
|
|
21803
|
+
prepopulation: "required_template",
|
|
21804
|
+
copyMode: "template_global",
|
|
21805
|
+
scope: "global",
|
|
21806
|
+
uniqueKey: ["key"],
|
|
21807
|
+
description: "Model catalog defaults are required by model runtime clients."
|
|
21808
|
+
},
|
|
21809
|
+
{
|
|
21810
|
+
component: "identity",
|
|
21811
|
+
table: "modelSlotConfigs",
|
|
21812
|
+
prepopulation: "required_template",
|
|
21813
|
+
copyMode: "template_global",
|
|
21814
|
+
scope: "global",
|
|
21815
|
+
uniqueKey: ["slot"],
|
|
21816
|
+
description: "Slot-level defaults are required before tenant overrides exist."
|
|
21817
|
+
},
|
|
21818
|
+
{
|
|
21819
|
+
component: "identity",
|
|
21820
|
+
table: "platformAudienceGrants",
|
|
21821
|
+
prepopulation: "runtime_data",
|
|
21822
|
+
copyMode: "none",
|
|
21823
|
+
description: "Audience grants are principal/group-specific access rows."
|
|
21824
|
+
},
|
|
21825
|
+
{
|
|
21826
|
+
component: "identity",
|
|
21827
|
+
table: "platformAudiences",
|
|
21828
|
+
prepopulation: "required_template",
|
|
21829
|
+
copyMode: "template_tenant_rewrite",
|
|
21830
|
+
scope: "tenant",
|
|
21831
|
+
uniqueKey: ["tenantId", "workspaceId", "audienceKey"],
|
|
21832
|
+
description: "Default tenant audience taxonomy rows are rewritten into each tenant."
|
|
21833
|
+
},
|
|
21834
|
+
{
|
|
21835
|
+
component: "identity",
|
|
21836
|
+
table: "platformPolicyDecisionLogs",
|
|
21837
|
+
prepopulation: "runtime_log",
|
|
21838
|
+
copyMode: "none",
|
|
21839
|
+
description: "Policy decisions are runtime audit logs."
|
|
21840
|
+
},
|
|
21841
|
+
{
|
|
21842
|
+
component: "identity",
|
|
21843
|
+
table: "projectGrants",
|
|
21844
|
+
prepopulation: "runtime_data",
|
|
21845
|
+
copyMode: "none",
|
|
21846
|
+
description: "Project/topic grants are principal or group-specific access rows."
|
|
21847
|
+
},
|
|
21848
|
+
{
|
|
21849
|
+
component: "identity",
|
|
21850
|
+
table: "reasoningPermissions",
|
|
21851
|
+
prepopulation: "runtime_data",
|
|
21852
|
+
copyMode: "none",
|
|
21853
|
+
description: "Reasoning permissions are principal-specific policy rows."
|
|
21854
|
+
},
|
|
21855
|
+
{
|
|
21856
|
+
component: "identity",
|
|
21857
|
+
table: "tenantApiKeys",
|
|
21858
|
+
prepopulation: "runtime_secret",
|
|
21859
|
+
copyMode: "none",
|
|
21860
|
+
description: "API keys are tenant credentials and must never be copied."
|
|
21861
|
+
},
|
|
21862
|
+
{
|
|
21863
|
+
component: "identity",
|
|
21864
|
+
table: "tenantConfig",
|
|
21865
|
+
prepopulation: "required_template",
|
|
21866
|
+
copyMode: "template_tenant_rewrite",
|
|
21867
|
+
scope: "tenant",
|
|
21868
|
+
uniqueKey: ["tenantId"],
|
|
21869
|
+
description: "Tenant-local config defaults are rewritten during bootstrap."
|
|
21870
|
+
},
|
|
21871
|
+
{
|
|
21872
|
+
component: "identity",
|
|
21873
|
+
table: "tenantIntegrations",
|
|
21874
|
+
prepopulation: "required_template",
|
|
21875
|
+
copyMode: "template_tenant_rewrite",
|
|
21876
|
+
scope: "tenant",
|
|
21877
|
+
uniqueKey: ["tenantId", "integrationKey"],
|
|
21878
|
+
description: "Non-secret integration descriptors are rewritten into each tenant."
|
|
21879
|
+
},
|
|
21880
|
+
{
|
|
21881
|
+
component: "identity",
|
|
21882
|
+
table: "tenantModelSlotBindings",
|
|
21883
|
+
prepopulation: "runtime_secret",
|
|
21884
|
+
copyMode: "none",
|
|
21885
|
+
description: "Tenant model slot bindings reference provider secrets and are runtime-only."
|
|
21886
|
+
},
|
|
21887
|
+
{
|
|
21888
|
+
component: "identity",
|
|
21889
|
+
table: "tenantPolicies",
|
|
21890
|
+
prepopulation: "required_template",
|
|
21891
|
+
copyMode: "template_tenant_rewrite",
|
|
21892
|
+
scope: "tenant",
|
|
21893
|
+
uniqueKey: ["tenantId", "workspaceId", "roleName"],
|
|
21894
|
+
description: "Default tenant policy roles are rewritten during bootstrap."
|
|
21895
|
+
},
|
|
21896
|
+
{
|
|
21897
|
+
component: "identity",
|
|
21898
|
+
table: "tenantProviderSecrets",
|
|
21899
|
+
prepopulation: "runtime_secret",
|
|
21900
|
+
copyMode: "none",
|
|
21901
|
+
description: "Provider secrets are credentials and must never be copied."
|
|
21902
|
+
},
|
|
21903
|
+
{
|
|
21904
|
+
component: "identity",
|
|
21905
|
+
table: "tenantProxyGatewayUsage",
|
|
21906
|
+
prepopulation: "runtime_log",
|
|
21907
|
+
copyMode: "none",
|
|
21908
|
+
description: "Proxy gateway usage rows are runtime telemetry."
|
|
21909
|
+
},
|
|
21910
|
+
{
|
|
21911
|
+
component: "identity",
|
|
21912
|
+
table: "tenantProxyTokenMints",
|
|
21913
|
+
prepopulation: "runtime_secret",
|
|
21914
|
+
copyMode: "none",
|
|
21915
|
+
description: "Proxy token mints are ephemeral secret-bearing runtime rows."
|
|
21916
|
+
},
|
|
21917
|
+
{
|
|
21918
|
+
component: "identity",
|
|
21919
|
+
table: "tenantSandboxAuditEvents",
|
|
21920
|
+
prepopulation: "runtime_log",
|
|
21921
|
+
copyMode: "none",
|
|
21922
|
+
description: "Sandbox audit rows are runtime security logs."
|
|
21923
|
+
},
|
|
21924
|
+
{
|
|
21925
|
+
component: "identity",
|
|
21926
|
+
table: "tenantSecrets",
|
|
21927
|
+
prepopulation: "runtime_secret",
|
|
21928
|
+
copyMode: "none",
|
|
21929
|
+
description: "Tenant secrets are credentials and must never be copied."
|
|
21930
|
+
},
|
|
21931
|
+
{
|
|
21932
|
+
component: "identity",
|
|
21933
|
+
table: "toolAcls",
|
|
21934
|
+
prepopulation: "required_template",
|
|
21935
|
+
copyMode: "template_global",
|
|
21936
|
+
scope: "global",
|
|
21937
|
+
uniqueKey: ["role", "toolName"],
|
|
21938
|
+
description: "Default role-to-tool grants are required for SDK/MCP tool access."
|
|
21939
|
+
},
|
|
21940
|
+
{
|
|
21941
|
+
component: "identity",
|
|
21942
|
+
table: "toolRegistry",
|
|
21943
|
+
prepopulation: "required_template",
|
|
21944
|
+
copyMode: "template_global",
|
|
21945
|
+
scope: "global",
|
|
21946
|
+
uniqueKey: ["toolName"],
|
|
21947
|
+
description: "Core tool catalog rows are required before pack or tenant tools exist."
|
|
21948
|
+
},
|
|
21949
|
+
{
|
|
21950
|
+
component: "identity",
|
|
21951
|
+
table: "users",
|
|
21952
|
+
prepopulation: "runtime_bootstrap",
|
|
21953
|
+
copyMode: "none",
|
|
21954
|
+
description: "Users are created from Clerk/MC principal resolution, not copied."
|
|
21955
|
+
}
|
|
21956
|
+
];
|
|
21957
|
+
TENANT_BOOTSTRAP_TABLE_REQUIREMENTS.filter(
|
|
21958
|
+
isCopyableSeedRequirement
|
|
21959
|
+
);
|
|
21960
|
+
TENANT_BOOTSTRAP_TABLE_REQUIREMENTS.filter(
|
|
21961
|
+
(entry) => !isCopyableSeedRequirement(entry)
|
|
21962
|
+
).map((entry) => entry.table);
|
|
21963
|
+
|
|
21964
|
+
// src/execution.ts
|
|
21965
|
+
var SCOPE_ALIAS_GROUPS = [];
|
|
21966
|
+
function createToolExecutionEnvelope(args) {
|
|
21967
|
+
return {
|
|
21968
|
+
toolName: args.toolName,
|
|
21969
|
+
params: args.params,
|
|
21970
|
+
contract: args.contract,
|
|
21971
|
+
transport: {
|
|
21972
|
+
kind: args.transportKind,
|
|
21973
|
+
surface: args.transportKind === "chat" ? "chat" : "mcp",
|
|
21974
|
+
normalizedAt: "handler_boundary"
|
|
21975
|
+
},
|
|
21976
|
+
auth: {
|
|
21977
|
+
mode: args.authMode
|
|
21978
|
+
},
|
|
21979
|
+
policy: {
|
|
21980
|
+
requiredScopes: args.requiredScopes,
|
|
21981
|
+
enforcement: "gateway"
|
|
21982
|
+
},
|
|
21983
|
+
audit: {
|
|
21984
|
+
source: "gateway_envelope",
|
|
21985
|
+
structuralFields: [
|
|
21986
|
+
"toolName",
|
|
21987
|
+
"code",
|
|
21988
|
+
"status",
|
|
21989
|
+
"correlationId",
|
|
21990
|
+
"policyTraceId",
|
|
21991
|
+
"invariant"
|
|
21992
|
+
]
|
|
20795
21993
|
}
|
|
20796
|
-
}
|
|
20797
|
-
|
|
20798
|
-
|
|
20799
|
-
|
|
20800
|
-
|
|
20801
|
-
|
|
20802
|
-
|
|
20803
|
-
|
|
20804
|
-
|
|
20805
|
-
|
|
20806
|
-
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
21994
|
+
};
|
|
21995
|
+
}
|
|
21996
|
+
function hasValue(value) {
|
|
21997
|
+
if (value === void 0 || value === null) {
|
|
21998
|
+
return false;
|
|
21999
|
+
}
|
|
22000
|
+
if (typeof value === "string") {
|
|
22001
|
+
return value.trim().length > 0;
|
|
22002
|
+
}
|
|
22003
|
+
if (Array.isArray(value)) {
|
|
22004
|
+
return value.length > 0;
|
|
22005
|
+
}
|
|
22006
|
+
return true;
|
|
22007
|
+
}
|
|
22008
|
+
function normalizeToolExecutionParams(params) {
|
|
22009
|
+
const normalized = { ...params };
|
|
22010
|
+
for (const aliases of SCOPE_ALIAS_GROUPS) {
|
|
22011
|
+
const sourceKey = aliases.find((key) => hasValue(normalized[key]));
|
|
22012
|
+
if (!sourceKey) {
|
|
22013
|
+
continue;
|
|
20810
22014
|
}
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
domain: "scope",
|
|
20816
|
-
surfaceClass: "platform_internal",
|
|
20817
|
-
path: "/scope/belief-lattice/coverage",
|
|
20818
|
-
sdkNamespace: "context",
|
|
20819
|
-
sdkMethod: "getLatticeCoverage",
|
|
20820
|
-
summary: "Read belief lattice coverage for a topic.",
|
|
20821
|
-
convex: {
|
|
20822
|
-
module: "contextCompiler",
|
|
20823
|
-
functionName: "getLatticeCoverage",
|
|
20824
|
-
kind: "query"
|
|
22015
|
+
for (const key of aliases) {
|
|
22016
|
+
if (!hasValue(normalized[key])) {
|
|
22017
|
+
normalized[key] = normalized[sourceKey];
|
|
22018
|
+
}
|
|
20825
22019
|
}
|
|
20826
|
-
}
|
|
20827
|
-
|
|
20828
|
-
|
|
20829
|
-
|
|
20830
|
-
|
|
20831
|
-
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
20843
|
-
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
|
|
20849
|
-
|
|
20850
|
-
const
|
|
20851
|
-
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
20857
|
-
|
|
20858
|
-
|
|
20859
|
-
|
|
20860
|
-
|
|
20861
|
-
|
|
20862
|
-
|
|
20863
|
-
|
|
20864
|
-
|
|
20865
|
-
|
|
20866
|
-
|
|
20867
|
-
|
|
20868
|
-
|
|
20869
|
-
|
|
20870
|
-
|
|
20871
|
-
|
|
20872
|
-
|
|
20873
|
-
|
|
20874
|
-
|
|
20875
|
-
|
|
20876
|
-
rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
|
|
20877
|
-
trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
|
|
20878
|
-
}),
|
|
20879
|
-
context
|
|
20880
|
-
);
|
|
22020
|
+
}
|
|
22021
|
+
return normalized;
|
|
22022
|
+
}
|
|
22023
|
+
function parseToolExecutionMetadata(result) {
|
|
22024
|
+
const raw = result.content[0]?.text;
|
|
22025
|
+
if (!raw) {
|
|
22026
|
+
return { isError: Boolean(result.isError) };
|
|
22027
|
+
}
|
|
22028
|
+
try {
|
|
22029
|
+
const payload = JSON.parse(raw);
|
|
22030
|
+
return {
|
|
22031
|
+
isError: Boolean(result.isError),
|
|
22032
|
+
code: typeof payload.code === "string" ? payload.code : void 0,
|
|
22033
|
+
status: typeof payload.status === "number" ? payload.status : void 0,
|
|
22034
|
+
correlationId: typeof payload.correlationId === "string" || payload.correlationId === null ? payload.correlationId : void 0,
|
|
22035
|
+
policyTraceId: typeof payload.policyTraceId === "string" || payload.policyTraceId === null ? payload.policyTraceId : void 0,
|
|
22036
|
+
invariant: typeof payload.invariant === "string" || payload.invariant === null ? payload.invariant : void 0
|
|
22037
|
+
};
|
|
22038
|
+
} catch {
|
|
22039
|
+
return { isError: Boolean(result.isError) };
|
|
22040
|
+
}
|
|
22041
|
+
}
|
|
22042
|
+
async function executeToolWithEnvelope(args) {
|
|
22043
|
+
await args.hooks?.onEnvelope?.(args.envelope);
|
|
22044
|
+
const result = await args.execute();
|
|
22045
|
+
const metadata = parseToolExecutionMetadata(result);
|
|
22046
|
+
await args.hooks?.onAuditEvent?.({
|
|
22047
|
+
toolName: args.envelope.toolName,
|
|
22048
|
+
contractName: args.envelope.contract.name,
|
|
22049
|
+
transportKind: args.envelope.transport.kind,
|
|
22050
|
+
authMode: args.envelope.auth.mode,
|
|
22051
|
+
requiredScopes: args.envelope.policy.requiredScopes,
|
|
22052
|
+
source: args.envelope.audit.source,
|
|
22053
|
+
...metadata
|
|
22054
|
+
});
|
|
22055
|
+
return result;
|
|
22056
|
+
}
|
|
22057
|
+
|
|
22058
|
+
// src/types.ts
|
|
22059
|
+
var McpHandlerError = class extends Error {
|
|
22060
|
+
code;
|
|
22061
|
+
status;
|
|
22062
|
+
suggestion;
|
|
22063
|
+
constructor(message, code = "INVALID_REQUEST", status = 400, suggestion) {
|
|
22064
|
+
super(message);
|
|
22065
|
+
this.name = "McpHandlerError";
|
|
22066
|
+
this.code = code;
|
|
22067
|
+
this.status = status;
|
|
22068
|
+
this.suggestion = suggestion;
|
|
22069
|
+
}
|
|
20881
22070
|
};
|
|
20882
|
-
|
|
20883
|
-
|
|
20884
|
-
|
|
20885
|
-
|
|
20886
|
-
|
|
20887
|
-
|
|
20888
|
-
|
|
20889
|
-
|
|
20890
|
-
|
|
20891
|
-
|
|
20892
|
-
|
|
20893
|
-
|
|
20894
|
-
|
|
20895
|
-
|
|
20896
|
-
|
|
20897
|
-
|
|
20898
|
-
|
|
20899
|
-
|
|
20900
|
-
|
|
20901
|
-
context
|
|
20902
|
-
);
|
|
20903
|
-
var codingContracts = [
|
|
20904
|
-
surfaceContract({
|
|
20905
|
-
name: "record_scope_learning",
|
|
20906
|
-
kind: "mutation",
|
|
20907
|
-
domain: "scope",
|
|
20908
|
-
surfaceClass: "platform_internal",
|
|
20909
|
-
path: "/scope/learnings",
|
|
20910
|
-
sdkNamespace: "context",
|
|
20911
|
-
sdkMethod: "recordScopeLearning",
|
|
20912
|
-
summary: "Record a scope-level learning to the reasoning graph.",
|
|
20913
|
-
args: recordScopeLearningArgs,
|
|
20914
|
-
input: recordScopeLearningArgs,
|
|
20915
|
-
convex: {
|
|
20916
|
-
module: "evidence",
|
|
20917
|
-
functionName: "create",
|
|
20918
|
-
kind: "mutation",
|
|
20919
|
-
inputProjection: learningInput
|
|
22071
|
+
|
|
22072
|
+
// src/handler-factory.ts
|
|
22073
|
+
function isMissing(value) {
|
|
22074
|
+
if (value === void 0 || value === null) {
|
|
22075
|
+
return true;
|
|
22076
|
+
}
|
|
22077
|
+
if (typeof value === "string") {
|
|
22078
|
+
return value.trim().length === 0;
|
|
22079
|
+
}
|
|
22080
|
+
if (Array.isArray(value)) {
|
|
22081
|
+
return value.length === 0;
|
|
22082
|
+
}
|
|
22083
|
+
return false;
|
|
22084
|
+
}
|
|
22085
|
+
function readString3(params, key, options = {}) {
|
|
22086
|
+
const value = params[key];
|
|
22087
|
+
if (value === void 0 || value === null) {
|
|
22088
|
+
if (options.required) {
|
|
22089
|
+
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
20920
22090
|
}
|
|
20921
|
-
|
|
20922
|
-
|
|
20923
|
-
|
|
20924
|
-
|
|
20925
|
-
|
|
20926
|
-
|
|
20927
|
-
|
|
20928
|
-
|
|
20929
|
-
|
|
20930
|
-
|
|
20931
|
-
|
|
20932
|
-
|
|
20933
|
-
|
|
20934
|
-
|
|
20935
|
-
|
|
20936
|
-
|
|
20937
|
-
...input,
|
|
20938
|
-
summary: input.summary ?? `Write policy ${String(input.action ?? "update")}`,
|
|
20939
|
-
sourceKind: "write_policy"
|
|
20940
|
-
},
|
|
20941
|
-
context
|
|
20942
|
-
)
|
|
22091
|
+
return;
|
|
22092
|
+
}
|
|
22093
|
+
if (typeof value !== "string") {
|
|
22094
|
+
throw new McpHandlerError(`Expected string parameter: ${key}`);
|
|
22095
|
+
}
|
|
22096
|
+
const trimmed = value.trim();
|
|
22097
|
+
if (!trimmed && options.required) {
|
|
22098
|
+
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
22099
|
+
}
|
|
22100
|
+
return trimmed || void 0;
|
|
22101
|
+
}
|
|
22102
|
+
function readNumber2(params, key, options = {}) {
|
|
22103
|
+
const value = params[key];
|
|
22104
|
+
if (value === void 0 || value === null) {
|
|
22105
|
+
if (options.required) {
|
|
22106
|
+
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
20943
22107
|
}
|
|
20944
|
-
|
|
20945
|
-
|
|
20946
|
-
|
|
20947
|
-
|
|
20948
|
-
|
|
20949
|
-
|
|
20950
|
-
|
|
20951
|
-
|
|
20952
|
-
|
|
20953
|
-
|
|
20954
|
-
|
|
20955
|
-
|
|
20956
|
-
functionName: "getByTopic",
|
|
20957
|
-
kind: "query",
|
|
20958
|
-
inputProjection: (input) => compactRecord4({
|
|
20959
|
-
topicId: input.topicId,
|
|
20960
|
-
limit: input.limit,
|
|
20961
|
-
status: input.status,
|
|
20962
|
-
userId: input.userId
|
|
20963
|
-
})
|
|
22108
|
+
return;
|
|
22109
|
+
}
|
|
22110
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
22111
|
+
throw new McpHandlerError(`Expected numeric parameter: ${key}`);
|
|
22112
|
+
}
|
|
22113
|
+
return value;
|
|
22114
|
+
}
|
|
22115
|
+
function readBoolean(params, key, options = {}) {
|
|
22116
|
+
const value = params[key];
|
|
22117
|
+
if (value === void 0 || value === null) {
|
|
22118
|
+
if (options.required) {
|
|
22119
|
+
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
20964
22120
|
}
|
|
20965
|
-
|
|
20966
|
-
|
|
20967
|
-
|
|
20968
|
-
|
|
20969
|
-
|
|
20970
|
-
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
20974
|
-
|
|
20975
|
-
|
|
20976
|
-
|
|
20977
|
-
|
|
20978
|
-
|
|
20979
|
-
|
|
20980
|
-
|
|
20981
|
-
|
|
20982
|
-
|
|
20983
|
-
|
|
20984
|
-
|
|
22121
|
+
return;
|
|
22122
|
+
}
|
|
22123
|
+
if (typeof value !== "boolean") {
|
|
22124
|
+
throw new McpHandlerError(`Expected boolean parameter: ${key}`);
|
|
22125
|
+
}
|
|
22126
|
+
return value;
|
|
22127
|
+
}
|
|
22128
|
+
function readStringArray(params, key) {
|
|
22129
|
+
const value = params[key];
|
|
22130
|
+
if (value === void 0 || value === null) {
|
|
22131
|
+
return;
|
|
22132
|
+
}
|
|
22133
|
+
if (!Array.isArray(value)) {
|
|
22134
|
+
throw new McpHandlerError(`Expected array parameter: ${key}`);
|
|
22135
|
+
}
|
|
22136
|
+
const values = value.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
|
|
22137
|
+
return values.length > 0 ? values : void 0;
|
|
22138
|
+
}
|
|
22139
|
+
function readTopicId4(params, options = {}) {
|
|
22140
|
+
const value = params.topicId;
|
|
22141
|
+
if (value === void 0 || value === null) {
|
|
22142
|
+
if (options.required) {
|
|
22143
|
+
throw new McpHandlerError("Missing required parameter: topicId");
|
|
20985
22144
|
}
|
|
20986
|
-
|
|
20987
|
-
|
|
20988
|
-
|
|
20989
|
-
|
|
20990
|
-
|
|
20991
|
-
|
|
20992
|
-
|
|
20993
|
-
|
|
20994
|
-
|
|
20995
|
-
|
|
20996
|
-
|
|
20997
|
-
|
|
20998
|
-
|
|
20999
|
-
|
|
21000
|
-
|
|
22145
|
+
return;
|
|
22146
|
+
}
|
|
22147
|
+
if (typeof value !== "string") {
|
|
22148
|
+
throw new McpHandlerError("Expected string parameter: topicId");
|
|
22149
|
+
}
|
|
22150
|
+
const trimmed = value.trim();
|
|
22151
|
+
if (!trimmed && options.required) {
|
|
22152
|
+
throw new McpHandlerError("Missing required parameter: topicId");
|
|
22153
|
+
}
|
|
22154
|
+
return trimmed || void 0;
|
|
22155
|
+
}
|
|
22156
|
+
function toMcpResult(payload) {
|
|
22157
|
+
return {
|
|
22158
|
+
content: [{ type: "text", text: JSON.stringify(payload) }]
|
|
22159
|
+
};
|
|
22160
|
+
}
|
|
22161
|
+
function toMcpError(error) {
|
|
22162
|
+
if (error instanceof McpHandlerError) {
|
|
22163
|
+
return {
|
|
22164
|
+
isError: true,
|
|
22165
|
+
content: [
|
|
22166
|
+
{
|
|
22167
|
+
type: "text",
|
|
22168
|
+
text: JSON.stringify({
|
|
22169
|
+
code: error.code,
|
|
22170
|
+
status: error.status,
|
|
22171
|
+
message: error.message,
|
|
22172
|
+
suggestion: error.suggestion ?? null
|
|
22173
|
+
})
|
|
22174
|
+
}
|
|
22175
|
+
]
|
|
22176
|
+
};
|
|
22177
|
+
}
|
|
22178
|
+
if (error instanceof LucernApiError) {
|
|
22179
|
+
return {
|
|
22180
|
+
isError: true,
|
|
22181
|
+
content: [
|
|
22182
|
+
{
|
|
22183
|
+
type: "text",
|
|
22184
|
+
text: JSON.stringify({
|
|
22185
|
+
code: error.code,
|
|
22186
|
+
status: error.status,
|
|
22187
|
+
message: error.message,
|
|
22188
|
+
invariant: error.invariant ?? null,
|
|
22189
|
+
suggestion: error.suggestion ?? null,
|
|
22190
|
+
correlationId: error.correlationId,
|
|
22191
|
+
policyTraceId: error.policyTraceId
|
|
22192
|
+
})
|
|
22193
|
+
}
|
|
22194
|
+
]
|
|
22195
|
+
};
|
|
22196
|
+
}
|
|
22197
|
+
const message = error instanceof Error ? error.message : "Tool execution failed.";
|
|
22198
|
+
return {
|
|
22199
|
+
isError: true,
|
|
22200
|
+
content: [
|
|
22201
|
+
{
|
|
22202
|
+
type: "text",
|
|
22203
|
+
text: JSON.stringify({
|
|
22204
|
+
code: "INTERNAL_ERROR",
|
|
22205
|
+
status: 500,
|
|
22206
|
+
message
|
|
22207
|
+
})
|
|
22208
|
+
}
|
|
22209
|
+
]
|
|
22210
|
+
};
|
|
22211
|
+
}
|
|
22212
|
+
function createNotImplementedHandler(name) {
|
|
22213
|
+
return async () => toMcpError(
|
|
22214
|
+
new McpHandlerError(
|
|
22215
|
+
`Tool not implemented yet: ${name}`,
|
|
22216
|
+
"NOT_IMPLEMENTED",
|
|
22217
|
+
501
|
|
22218
|
+
)
|
|
22219
|
+
);
|
|
22220
|
+
}
|
|
22221
|
+
function validateRequired(params, contract) {
|
|
22222
|
+
for (const key of contract.required) {
|
|
22223
|
+
if (isMissing(params[key])) {
|
|
22224
|
+
throw new McpHandlerError(`Missing required parameter: ${key}`);
|
|
21001
22225
|
}
|
|
21002
|
-
}
|
|
21003
|
-
|
|
21004
|
-
|
|
21005
|
-
|
|
21006
|
-
|
|
21007
|
-
|
|
21008
|
-
|
|
21009
|
-
|
|
21010
|
-
|
|
21011
|
-
|
|
21012
|
-
convex: {
|
|
21013
|
-
module: "evidence",
|
|
21014
|
-
functionName: "getByTopic",
|
|
21015
|
-
kind: "query",
|
|
21016
|
-
inputProjection: (input) => compactRecord4({
|
|
21017
|
-
topicId: input.topicId ?? input.query,
|
|
21018
|
-
limit: input.limit,
|
|
21019
|
-
status: input.status,
|
|
21020
|
-
userId: input.userId
|
|
21021
|
-
})
|
|
22226
|
+
}
|
|
22227
|
+
}
|
|
22228
|
+
function contractToHandler(contract, executor) {
|
|
22229
|
+
return async (params) => {
|
|
22230
|
+
try {
|
|
22231
|
+
validateRequired(params, contract);
|
|
22232
|
+
const payload = await executor(params);
|
|
22233
|
+
return toMcpResult(payload);
|
|
22234
|
+
} catch (error) {
|
|
22235
|
+
return toMcpError(error);
|
|
21022
22236
|
}
|
|
21023
|
-
}
|
|
21024
|
-
|
|
22237
|
+
};
|
|
22238
|
+
}
|
|
21025
22239
|
|
|
21026
|
-
//
|
|
21027
|
-
var
|
|
21028
|
-
|
|
21029
|
-
|
|
21030
|
-
|
|
21031
|
-
|
|
21032
|
-
|
|
21033
|
-
|
|
21034
|
-
|
|
21035
|
-
|
|
21036
|
-
|
|
21037
|
-
|
|
21038
|
-
|
|
21039
|
-
|
|
21040
|
-
|
|
21041
|
-
|
|
21042
|
-
|
|
21043
|
-
|
|
21044
|
-
|
|
21045
|
-
|
|
22240
|
+
// src/handlers/beliefs.ts
|
|
22241
|
+
var AMBIGUOUS_SCALAR_SUGGESTION = "Use opinion tuple (b, d, u, a) or an @lucern/sdk opinionFromBaseRate/opinionFromDogmatic/opinionFromProjected helper.";
|
|
22242
|
+
function readOpinionTuple(params) {
|
|
22243
|
+
const belief = readNumber2(params, "belief");
|
|
22244
|
+
const disbelief = readNumber2(params, "disbelief");
|
|
22245
|
+
const uncertainty = readNumber2(params, "uncertainty");
|
|
22246
|
+
const baseRate = readNumber2(params, "baseRate");
|
|
22247
|
+
const tupleValues = [belief, disbelief, uncertainty, baseRate];
|
|
22248
|
+
const providedCount = tupleValues.filter(
|
|
22249
|
+
(value) => value !== void 0
|
|
22250
|
+
).length;
|
|
22251
|
+
if (providedCount === 0) {
|
|
22252
|
+
if (readNumber2(params, "confidence") !== void 0) {
|
|
22253
|
+
throw new McpHandlerError(
|
|
22254
|
+
"Scalar confidence input is ambiguous without an explicit subjective-logic interpretation.",
|
|
22255
|
+
"AMBIGUOUS_SCALAR",
|
|
22256
|
+
400,
|
|
22257
|
+
AMBIGUOUS_SCALAR_SUGGESTION
|
|
22258
|
+
);
|
|
22259
|
+
}
|
|
22260
|
+
throw new McpHandlerError(
|
|
22261
|
+
"Missing required opinion tuple: belief, disbelief, uncertainty, and baseRate are required.",
|
|
22262
|
+
"INVALID_REQUEST",
|
|
22263
|
+
400
|
|
22264
|
+
);
|
|
22265
|
+
}
|
|
22266
|
+
if (providedCount !== tupleValues.length) {
|
|
22267
|
+
throw new McpHandlerError(
|
|
22268
|
+
"Incomplete opinion tuple: belief, disbelief, uncertainty, and baseRate must all be provided together.",
|
|
22269
|
+
"INVALID_REQUEST",
|
|
22270
|
+
400
|
|
22271
|
+
);
|
|
22272
|
+
}
|
|
22273
|
+
return {
|
|
22274
|
+
b: belief,
|
|
22275
|
+
d: disbelief,
|
|
22276
|
+
u: uncertainty,
|
|
22277
|
+
a: baseRate
|
|
22278
|
+
};
|
|
22279
|
+
}
|
|
22280
|
+
function createBeliefHandlers(context) {
|
|
22281
|
+
const beliefs = createBeliefsClient(context.sdkConfig);
|
|
22282
|
+
const graph = createGraphClient(context.sdkConfig);
|
|
22283
|
+
return {
|
|
22284
|
+
create_belief: contractToHandler(
|
|
22285
|
+
MCP_TOOL_CONTRACTS.create_belief,
|
|
22286
|
+
async (params) => {
|
|
22287
|
+
const result = await beliefs.createBelief({
|
|
22288
|
+
canonicalText: readString3(params, "canonicalText", {
|
|
22289
|
+
required: true
|
|
22290
|
+
}),
|
|
22291
|
+
topicId: readTopicId4(params, { required: true }),
|
|
22292
|
+
layer: readString3(params, "layer"),
|
|
22293
|
+
domain: readString3(params, "domain"),
|
|
22294
|
+
subtype: readString3(params, "nodeType"),
|
|
22295
|
+
baseRate: readNumber2(params, "baseRate", { required: true })
|
|
22296
|
+
});
|
|
22297
|
+
return {
|
|
22298
|
+
nodeId: result.data.nodeId,
|
|
22299
|
+
globalId: result.data.globalId,
|
|
22300
|
+
status: result.data.status ?? "unscored"
|
|
22301
|
+
};
|
|
22302
|
+
}
|
|
22303
|
+
),
|
|
22304
|
+
refine_belief: contractToHandler(
|
|
22305
|
+
MCP_TOOL_CONTRACTS.refine_belief,
|
|
22306
|
+
async (params) => {
|
|
22307
|
+
const nodeId = readString3(params, "nodeId", { required: true });
|
|
22308
|
+
const canonicalText = readString3(params, "canonicalText", {
|
|
22309
|
+
required: true
|
|
22310
|
+
});
|
|
22311
|
+
const rationale = readString3(params, "rationale");
|
|
22312
|
+
const result = await beliefs.refineBelief(nodeId, {
|
|
22313
|
+
canonicalText,
|
|
22314
|
+
rationale
|
|
22315
|
+
});
|
|
22316
|
+
return {
|
|
22317
|
+
nodeId: result.data.nodeId ?? nodeId,
|
|
22318
|
+
canonicalText: result.data.canonicalText ?? canonicalText,
|
|
22319
|
+
updatedAt: result.data.updatedAt ?? Date.now()
|
|
22320
|
+
};
|
|
22321
|
+
}
|
|
22322
|
+
),
|
|
22323
|
+
modulate_confidence: contractToHandler(
|
|
22324
|
+
MCP_TOOL_CONTRACTS.modulate_confidence,
|
|
22325
|
+
async (params) => {
|
|
22326
|
+
const nodeId = readString3(params, "nodeId", { required: true });
|
|
22327
|
+
const opinion = readOpinionTuple(params);
|
|
22328
|
+
const result = await beliefs.modulateConfidence(nodeId, {
|
|
22329
|
+
opinion,
|
|
22330
|
+
trigger: readString3(params, "trigger", { required: true }),
|
|
22331
|
+
rationale: readString3(params, "rationale", { required: true }),
|
|
22332
|
+
triggeringEvidenceId: readString3(params, "triggeringEvidenceId"),
|
|
22333
|
+
triggeringQuestionId: readString3(params, "triggeringQuestionId"),
|
|
22334
|
+
triggeringAnswerId: readString3(params, "triggeringAnswerId"),
|
|
22335
|
+
triggeringContradictionId: readString3(
|
|
22336
|
+
params,
|
|
22337
|
+
"triggeringContradictionId"
|
|
22338
|
+
),
|
|
22339
|
+
triggeringWorktreeId: readString3(params, "triggeringWorktreeId")
|
|
22340
|
+
});
|
|
22341
|
+
return {
|
|
22342
|
+
nodeId,
|
|
22343
|
+
newConfidence: result.data.newConfidence ?? result.data.confidence ?? opinion.b + opinion.a * opinion.u,
|
|
22344
|
+
previousConfidence: result.data.previousConfidence ?? null,
|
|
22345
|
+
trigger: readString3(params, "trigger", { required: true })
|
|
22346
|
+
};
|
|
22347
|
+
}
|
|
22348
|
+
),
|
|
22349
|
+
fork_belief: contractToHandler(
|
|
22350
|
+
MCP_TOOL_CONTRACTS.fork_belief,
|
|
22351
|
+
async (params) => {
|
|
22352
|
+
const nodeId = readString3(params, "nodeId", { required: true });
|
|
22353
|
+
const forkReason = readString3(params, "forkReason", {
|
|
22354
|
+
required: true
|
|
22355
|
+
});
|
|
22356
|
+
const result = await beliefs.forkBelief(nodeId, {
|
|
22357
|
+
newFormulation: readString3(params, "newFormulation", {
|
|
22358
|
+
required: true
|
|
22359
|
+
}),
|
|
22360
|
+
forkReason
|
|
22361
|
+
});
|
|
22362
|
+
return {
|
|
22363
|
+
nodeId: result.data.nodeId,
|
|
22364
|
+
parentNodeId: result.data.parentNodeId ?? nodeId,
|
|
22365
|
+
forkReason: result.data.forkReason ?? forkReason
|
|
22366
|
+
};
|
|
22367
|
+
}
|
|
22368
|
+
),
|
|
22369
|
+
archive_belief: contractToHandler(
|
|
22370
|
+
MCP_TOOL_CONTRACTS.archive_belief,
|
|
22371
|
+
async (params) => {
|
|
22372
|
+
const nodeId = readString3(params, "nodeId", { required: true });
|
|
22373
|
+
const rationale = readString3(params, "rationale");
|
|
22374
|
+
const result = await graph.updateNode({
|
|
22375
|
+
nodeId,
|
|
22376
|
+
status: "archived",
|
|
22377
|
+
metadata: rationale ? {
|
|
22378
|
+
archiveRationale: rationale
|
|
22379
|
+
} : void 0
|
|
22380
|
+
});
|
|
22381
|
+
return {
|
|
22382
|
+
nodeId: result.data.nodeId ?? nodeId,
|
|
22383
|
+
status: "archived"
|
|
22384
|
+
};
|
|
22385
|
+
}
|
|
22386
|
+
)
|
|
22387
|
+
};
|
|
22388
|
+
}
|
|
22389
|
+
var PUBLIC_TOPIC_PREFIX = "top_";
|
|
22390
|
+
function isNonEmptyString(value) {
|
|
22391
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
22392
|
+
}
|
|
22393
|
+
function encodePublicTopicId(topicId) {
|
|
22394
|
+
if (!isNonEmptyString(topicId)) {
|
|
22395
|
+
return void 0;
|
|
22396
|
+
}
|
|
22397
|
+
return topicId.startsWith(PUBLIC_TOPIC_PREFIX) ? topicId : `${PUBLIC_TOPIC_PREFIX}${topicId}`;
|
|
22398
|
+
}
|
|
22399
|
+
function readExistingContext(filePath) {
|
|
22400
|
+
try {
|
|
22401
|
+
if (!fs.existsSync(filePath)) {
|
|
22402
|
+
return {};
|
|
21046
22403
|
}
|
|
21047
|
-
|
|
21048
|
-
|
|
22404
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
22405
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
22406
|
+
} catch {
|
|
22407
|
+
return {};
|
|
22408
|
+
}
|
|
22409
|
+
}
|
|
22410
|
+
function writeLocalLucernContext(context, cwd = process.cwd()) {
|
|
22411
|
+
try {
|
|
22412
|
+
const filePath = path.join(cwd, ".lucern.json");
|
|
22413
|
+
const previous = readExistingContext(filePath);
|
|
22414
|
+
const topicId = encodePublicTopicId(context.topicId ?? previous.topicId);
|
|
22415
|
+
const topicName = context.topicName ?? previous.topicName;
|
|
22416
|
+
const normalized = {
|
|
22417
|
+
...previous,
|
|
22418
|
+
...context,
|
|
22419
|
+
...topicId ? { topicId, projectId: topicId } : {},
|
|
22420
|
+
...topicName ? { topicName, projectName: topicName } : {},
|
|
22421
|
+
lastUpdated: context.lastUpdated ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
22422
|
+
};
|
|
22423
|
+
fs.writeFileSync(
|
|
22424
|
+
filePath,
|
|
22425
|
+
`${JSON.stringify(normalized, null, 2)}
|
|
22426
|
+
`,
|
|
22427
|
+
"utf8"
|
|
22428
|
+
);
|
|
22429
|
+
} catch {
|
|
22430
|
+
}
|
|
22431
|
+
}
|
|
21049
22432
|
|
|
21050
|
-
//
|
|
21051
|
-
|
|
21052
|
-
|
|
21053
|
-
|
|
21054
|
-
|
|
21055
|
-
|
|
21056
|
-
|
|
21057
|
-
|
|
21058
|
-
|
|
21059
|
-
|
|
21060
|
-
|
|
21061
|
-
|
|
21062
|
-
|
|
21063
|
-
|
|
21064
|
-
|
|
21065
|
-
|
|
21066
|
-
|
|
21067
|
-
|
|
21068
|
-
|
|
21069
|
-
|
|
21070
|
-
|
|
21071
|
-
|
|
21072
|
-
|
|
21073
|
-
|
|
21074
|
-
|
|
21075
|
-
)
|
|
22433
|
+
// src/handlers/context.ts
|
|
22434
|
+
function readResultString(value, key) {
|
|
22435
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
22436
|
+
return;
|
|
22437
|
+
}
|
|
22438
|
+
const candidate = value[key];
|
|
22439
|
+
return typeof candidate === "string" && candidate.trim().length > 0 ? candidate.trim() : void 0;
|
|
22440
|
+
}
|
|
22441
|
+
function createContextHandlers(context) {
|
|
22442
|
+
const compiler = createContextClient(context.sdkConfig);
|
|
22443
|
+
return {
|
|
22444
|
+
compile_context: contractToHandler(
|
|
22445
|
+
MCP_TOOL_CONTRACTS.compile_context,
|
|
22446
|
+
async (params) => {
|
|
22447
|
+
const topicId = readTopicId4(params, { required: true });
|
|
22448
|
+
const response = await compiler.compile(
|
|
22449
|
+
topicId,
|
|
22450
|
+
{
|
|
22451
|
+
...readString3(params, "query") ? { query: readString3(params, "query") } : {},
|
|
22452
|
+
...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
|
|
22453
|
+
...readString3(params, "ranking") ? {
|
|
22454
|
+
ranking: readString3(params, "ranking")
|
|
22455
|
+
} : {},
|
|
22456
|
+
...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
|
|
22457
|
+
...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
|
|
22458
|
+
...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
|
|
22459
|
+
}
|
|
22460
|
+
);
|
|
22461
|
+
writeLocalLucernContext({
|
|
22462
|
+
topicId: readResultString(response.data, "topicId") ?? topicId,
|
|
22463
|
+
topicName: readResultString(response.data, "topicName"),
|
|
22464
|
+
activeWorktree: null
|
|
22465
|
+
});
|
|
22466
|
+
return response.data;
|
|
22467
|
+
}
|
|
22468
|
+
)
|
|
22469
|
+
};
|
|
22470
|
+
}
|
|
22471
|
+
|
|
22472
|
+
// src/handlers/contradictions.ts
|
|
22473
|
+
function createContradictionHandlers(context) {
|
|
22474
|
+
const lucern = createLucernClient(context.sdkConfig);
|
|
22475
|
+
return {
|
|
22476
|
+
flag_contradiction: contractToHandler(
|
|
22477
|
+
MCP_TOOL_CONTRACTS.flag_contradiction,
|
|
22478
|
+
async (params) => {
|
|
22479
|
+
const beliefA = readString3(params, "beliefA", { required: true });
|
|
22480
|
+
const beliefB = readString3(params, "beliefB", { required: true });
|
|
22481
|
+
const description = readString3(params, "description", {
|
|
22482
|
+
required: true
|
|
22483
|
+
});
|
|
22484
|
+
const topicId = readTopicId4(params, { required: true });
|
|
22485
|
+
const severity = readString3(params, "severity") ?? "medium";
|
|
22486
|
+
const defeatType = readString3(params, "defeatType") ?? "rebuts";
|
|
22487
|
+
const contradiction = await lucern.contradictions.flag({
|
|
22488
|
+
beliefA,
|
|
22489
|
+
beliefB,
|
|
22490
|
+
description,
|
|
22491
|
+
topicId,
|
|
22492
|
+
severity,
|
|
22493
|
+
defeatType
|
|
22494
|
+
});
|
|
22495
|
+
return {
|
|
22496
|
+
contradictionId: contradiction.contradictionId,
|
|
22497
|
+
status: contradiction.status,
|
|
22498
|
+
beliefA: contradiction.beliefA,
|
|
22499
|
+
beliefB: contradiction.beliefB
|
|
22500
|
+
};
|
|
22501
|
+
}
|
|
22502
|
+
)
|
|
22503
|
+
};
|
|
22504
|
+
}
|
|
22505
|
+
|
|
22506
|
+
// src/handlers/edges.ts
|
|
22507
|
+
function createEdgeHandlers(context) {
|
|
22508
|
+
const lucern = createLucernClient(context.sdkConfig);
|
|
22509
|
+
return {
|
|
22510
|
+
create_edge: contractToHandler(
|
|
22511
|
+
MCP_TOOL_CONTRACTS.create_edge,
|
|
22512
|
+
async (params) => {
|
|
22513
|
+
const sourceId = readString3(params, "sourceId", { required: true });
|
|
22514
|
+
const targetId = readString3(params, "targetId", { required: true });
|
|
22515
|
+
const edgeType = readString3(params, "edgeType", { required: true });
|
|
22516
|
+
const confidence = readNumber2(params, "confidence");
|
|
22517
|
+
const weight = readNumber2(params, "weight");
|
|
22518
|
+
const contextText = readString3(params, "context") ?? readString3(params, "reasoning");
|
|
22519
|
+
const edge = await lucern.edges.create({
|
|
22520
|
+
sourceId,
|
|
22521
|
+
targetId,
|
|
22522
|
+
edgeType,
|
|
22523
|
+
confidence,
|
|
22524
|
+
weight,
|
|
22525
|
+
context: contextText
|
|
22526
|
+
});
|
|
22527
|
+
return {
|
|
22528
|
+
globalId: edge.globalId ?? edge.edgeId ?? "",
|
|
22529
|
+
edgeType: edge.edgeType ?? edgeType,
|
|
22530
|
+
fromLayer: edge.fromLayer ?? "unknown",
|
|
22531
|
+
toLayer: edge.toLayer ?? "unknown"
|
|
22532
|
+
};
|
|
22533
|
+
}
|
|
22534
|
+
)
|
|
22535
|
+
};
|
|
22536
|
+
}
|
|
22537
|
+
|
|
22538
|
+
// src/handlers/evidence.ts
|
|
22539
|
+
function readMetadata(params) {
|
|
22540
|
+
const metadata = params.metadata;
|
|
22541
|
+
return metadata && typeof metadata === "object" && !Array.isArray(metadata) ? metadata : void 0;
|
|
22542
|
+
}
|
|
22543
|
+
function createEvidenceHandlers(context) {
|
|
22544
|
+
const lucern = createLucernClient(context.sdkConfig);
|
|
22545
|
+
return {
|
|
22546
|
+
create_evidence: contractToHandler(
|
|
22547
|
+
MCP_TOOL_CONTRACTS.create_evidence,
|
|
22548
|
+
async (params) => {
|
|
22549
|
+
const response = await lucern.evidence.create({
|
|
22550
|
+
topicId: readTopicId4(params, { required: true }),
|
|
22551
|
+
text: readString3(params, "text", { required: true }),
|
|
22552
|
+
source: readString3(params, "source"),
|
|
22553
|
+
targetId: readString3(params, "targetId"),
|
|
22554
|
+
weight: readNumber2(params, "weight"),
|
|
22555
|
+
metadata: readMetadata(params),
|
|
22556
|
+
title: readString3(params, "title"),
|
|
22557
|
+
content: readString3(params, "content"),
|
|
22558
|
+
contentType: readString3(params, "contentType"),
|
|
22559
|
+
kind: readString3(params, "kind")
|
|
22560
|
+
});
|
|
22561
|
+
return response.data;
|
|
22562
|
+
}
|
|
22563
|
+
),
|
|
22564
|
+
get_evidence: contractToHandler(
|
|
22565
|
+
MCP_TOOL_CONTRACTS.get_evidence,
|
|
22566
|
+
async (params) => {
|
|
22567
|
+
const response = await lucern.evidence.get(
|
|
22568
|
+
readString3(params, "id", { required: true })
|
|
22569
|
+
);
|
|
22570
|
+
return response.data;
|
|
22571
|
+
}
|
|
22572
|
+
),
|
|
22573
|
+
list_evidence: contractToHandler(
|
|
22574
|
+
MCP_TOOL_CONTRACTS.list_evidence,
|
|
22575
|
+
async (params) => {
|
|
22576
|
+
const response = await lucern.evidence.list({
|
|
22577
|
+
topicId: readTopicId4(params),
|
|
22578
|
+
targetId: readString3(params, "targetId"),
|
|
22579
|
+
limit: readNumber2(params, "limit"),
|
|
22580
|
+
cursor: readString3(params, "cursor")
|
|
22581
|
+
});
|
|
22582
|
+
return response.data;
|
|
22583
|
+
}
|
|
22584
|
+
),
|
|
22585
|
+
link_evidence: contractToHandler(
|
|
22586
|
+
MCP_TOOL_CONTRACTS.link_evidence,
|
|
22587
|
+
async (params) => {
|
|
22588
|
+
const response = await lucern.evidence.link({
|
|
22589
|
+
evidenceId: readString3(params, "evidenceId", { required: true }),
|
|
22590
|
+
targetId: readString3(params, "targetId", { required: true }),
|
|
22591
|
+
weight: readNumber2(params, "weight"),
|
|
22592
|
+
rationale: readString3(params, "rationale")
|
|
22593
|
+
});
|
|
22594
|
+
return response.data;
|
|
22595
|
+
}
|
|
22596
|
+
),
|
|
22597
|
+
search_evidence: contractToHandler(
|
|
22598
|
+
MCP_TOOL_CONTRACTS.search_evidence,
|
|
22599
|
+
async (params) => {
|
|
22600
|
+
const response = await lucern.evidence.search({
|
|
22601
|
+
q: readString3(params, "q") ?? readString3(params, "query", { required: true }),
|
|
22602
|
+
topicId: readTopicId4(params),
|
|
22603
|
+
targetId: readString3(params, "targetId"),
|
|
22604
|
+
limit: readNumber2(params, "limit"),
|
|
22605
|
+
cursor: readString3(params, "cursor")
|
|
22606
|
+
});
|
|
22607
|
+
return response.data;
|
|
22608
|
+
}
|
|
22609
|
+
),
|
|
22610
|
+
add_evidence: contractToHandler(
|
|
22611
|
+
MCP_TOOL_CONTRACTS.add_evidence,
|
|
22612
|
+
async (params) => {
|
|
22613
|
+
return lucern.evidence.add({
|
|
22614
|
+
canonicalText: readString3(params, "canonicalText", { required: true }),
|
|
22615
|
+
topicId: readTopicId4(params, { required: true }),
|
|
22616
|
+
sourceUrl: readString3(params, "sourceUrl"),
|
|
22617
|
+
supports: {
|
|
22618
|
+
nodeId: readString3(params, "targetNodeId", { required: true }),
|
|
22619
|
+
weight: readNumber2(params, "weight") ?? 1,
|
|
22620
|
+
reasoning: readString3(params, "reasoning")
|
|
22621
|
+
},
|
|
22622
|
+
title: readString3(params, "title"),
|
|
22623
|
+
content: readString3(params, "content"),
|
|
22624
|
+
contentType: readString3(params, "contentType"),
|
|
22625
|
+
metadata: readMetadata(params)
|
|
22626
|
+
});
|
|
22627
|
+
}
|
|
22628
|
+
),
|
|
22629
|
+
link_evidence_to_belief: contractToHandler(
|
|
22630
|
+
MCP_TOOL_CONTRACTS.link_evidence_to_belief,
|
|
22631
|
+
async (params) => {
|
|
22632
|
+
return lucern.evidence.linkToBelief({
|
|
22633
|
+
evidenceId: readString3(params, "evidenceId", { required: true }),
|
|
22634
|
+
beliefId: readString3(params, "beliefId", { required: true }),
|
|
22635
|
+
weight: readNumber2(params, "weight", { required: true }),
|
|
22636
|
+
rationale: readString3(params, "rationale")
|
|
22637
|
+
});
|
|
22638
|
+
}
|
|
22639
|
+
)
|
|
22640
|
+
};
|
|
22641
|
+
}
|
|
21076
22642
|
|
|
21077
22643
|
// src/handlers/functionSurface.ts
|
|
21078
22644
|
function camelCaseToolName(name) {
|
|
@@ -21908,6 +23474,21 @@ function mapWorktreeStatus(status) {
|
|
|
21908
23474
|
}
|
|
21909
23475
|
return;
|
|
21910
23476
|
}
|
|
23477
|
+
function readMergeOutcomes(value) {
|
|
23478
|
+
if (!Array.isArray(value)) {
|
|
23479
|
+
return [];
|
|
23480
|
+
}
|
|
23481
|
+
return value.map((entry) => {
|
|
23482
|
+
if (typeof entry === "string") {
|
|
23483
|
+
const finding = entry.trim();
|
|
23484
|
+
return finding ? finding : null;
|
|
23485
|
+
}
|
|
23486
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
23487
|
+
return null;
|
|
23488
|
+
}
|
|
23489
|
+
return entry;
|
|
23490
|
+
}).filter((entry) => entry !== null);
|
|
23491
|
+
}
|
|
21911
23492
|
function createWorktreeHandlers(context) {
|
|
21912
23493
|
const workflow = createWorkflowClient(context.sdkConfig);
|
|
21913
23494
|
return {
|
|
@@ -22018,7 +23599,7 @@ function createWorktreeHandlers(context) {
|
|
|
22018
23599
|
),
|
|
22019
23600
|
merge: contractToHandler(MCP_TOOL_CONTRACTS.merge, async (params) => {
|
|
22020
23601
|
const worktreeId = readString3(params, "worktreeId", { required: true });
|
|
22021
|
-
const outcomes =
|
|
23602
|
+
const outcomes = readMergeOutcomes(params.outcomes);
|
|
22022
23603
|
const result = await workflow.merge(worktreeId, {
|
|
22023
23604
|
outcomes,
|
|
22024
23605
|
summary: readString3(params, "summary")
|