@lucern/mcp 0.3.0-alpha.7 → 0.3.0-alpha.8

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/index.js CHANGED
@@ -300,9 +300,14 @@ function loadProfile(options) {
300
300
  const profiles = readProfilesFile(profilesPath());
301
301
  const localEnv = options.readLocalEnv === false ? {} : readLocalEnvFiles(options.cwd);
302
302
  const mergedEnv = { ...localEnv, ...options.env };
303
- const selected = options.profileName ?? mergedEnv.LUCERN_PROFILE ?? profiles.activeProfile ?? credentials.LUCERN_PROFILE ?? "default";
304
- const savedProfile = profiles.profiles?.[selected] ?? {};
305
303
  const envProfile = profileFromEnvironment(mergedEnv);
304
+ const hasEnvCredentials = Boolean(
305
+ envProfile.apiKey || envProfile.userToken || envProfile.packKey
306
+ );
307
+ const explicitProfileSelected = options.profileName !== void 0 || mergedEnv.LUCERN_PROFILE !== void 0;
308
+ const selectedProfile = options.profileName ?? mergedEnv.LUCERN_PROFILE ?? profiles.activeProfile ?? credentials.LUCERN_PROFILE ?? "default";
309
+ const selected = hasEnvCredentials && !explicitProfileSelected ? "env" : selectedProfile;
310
+ const savedProfile = hasEnvCredentials && !explicitProfileSelected ? {} : profiles.profiles?.[selectedProfile] ?? {};
306
311
  const credentialsProfile = {
307
312
  apiKey: credentials.LUCERN_API_KEY,
308
313
  userToken: readFirst(credentials, ["LUCERN_SESSION_TOKEN", "LUCERN_USER_TOKEN"]),
@@ -8083,15 +8088,15 @@ var IDENTITY_WHOAMI = {
8083
8088
  };
8084
8089
  var COMPILE_CONTEXT = {
8085
8090
  name: "compile_context",
8086
- description: "Compile a focused reasoning context for a topic. Like `git log --graph --decorate` for the reasoning substrate \u2014 returns the canonical Pillar 3 context pack through the public API shape.",
8091
+ description: "Compile a focused reasoning context. If topicId is omitted, Lucern resolves the best topic from the query. Like `git log --graph --decorate` for the reasoning substrate \u2014 returns the canonical Pillar 3 context pack through the public API shape.",
8087
8092
  parameters: {
8088
8093
  topicId: {
8089
8094
  type: "string",
8090
- description: "Topic scope ID to compile"
8095
+ description: "Optional topic scope ID. Omit to resolve the topic from query."
8091
8096
  },
8092
8097
  query: {
8093
8098
  type: "string",
8094
- description: "Optional focus query used to rank context items"
8099
+ description: "Focus query used to resolve the topic and rank context items. Required when topicId is omitted."
8095
8100
  },
8096
8101
  budget: {
8097
8102
  type: "number",
@@ -8115,7 +8120,7 @@ var COMPILE_CONTEXT = {
8115
8120
  description: "Include related ontological entities in the compiled result"
8116
8121
  }
8117
8122
  },
8118
- required: ["topicId"],
8123
+ required: [],
8119
8124
  response: {
8120
8125
  description: "Compiled context pack for the requested topic",
8121
8126
  fields: {
@@ -10626,7 +10631,7 @@ var contextContracts = [
10626
10631
  path: "/context/compile",
10627
10632
  sdkNamespace: "context",
10628
10633
  sdkMethod: "compileContext",
10629
- summary: "Compile a focused reasoning context for a topic.",
10634
+ summary: "Compile a focused reasoning context, resolving topic from query when omitted.",
10630
10635
  convex: {
10631
10636
  module: "contextCompiler",
10632
10637
  functionName: "compile",
@@ -18961,50 +18966,55 @@ function cleanNumber(value) {
18961
18966
  function cleanBoolean(value) {
18962
18967
  return typeof value === "boolean" ? value : void 0;
18963
18968
  }
18964
- function buildCompileContextRequest(topicId, input = {}) {
18965
- const payload = { topicId };
18966
- const query5 = cleanString4(input.query);
18969
+ function buildCompileContextRequest(topicIdOrInput = {}, input = {}) {
18970
+ const effectiveInput = typeof topicIdOrInput === "string" ? input : topicIdOrInput;
18971
+ const payload = {};
18972
+ const topicId = typeof topicIdOrInput === "string" ? cleanString4(topicIdOrInput) : cleanString4(effectiveInput.topicId);
18973
+ if (topicId) {
18974
+ payload.topicId = topicId;
18975
+ }
18976
+ const query5 = cleanString4(effectiveInput.query);
18967
18977
  if (query5) {
18968
18978
  payload.query = query5;
18969
18979
  }
18970
- const budget = cleanNumber(input.budget) ?? cleanNumber(input.tokenBudget);
18980
+ const budget = cleanNumber(effectiveInput.budget) ?? cleanNumber(effectiveInput.tokenBudget);
18971
18981
  if (budget !== void 0) {
18972
18982
  payload.budget = budget;
18973
18983
  }
18974
- const ranking = cleanString4(input.ranking) ?? cleanString4(input.rankingProfile);
18984
+ const ranking = cleanString4(effectiveInput.ranking) ?? cleanString4(effectiveInput.rankingProfile);
18975
18985
  if (ranking) {
18976
18986
  payload.ranking = ranking;
18977
18987
  }
18978
- const limit = cleanNumber(input.limit);
18988
+ const limit = cleanNumber(effectiveInput.limit);
18979
18989
  if (limit !== void 0) {
18980
18990
  payload.limit = limit;
18981
18991
  }
18982
- const maxDepth = cleanNumber(input.maxDepth);
18992
+ const maxDepth = cleanNumber(effectiveInput.maxDepth);
18983
18993
  if (maxDepth !== void 0) {
18984
18994
  payload.maxDepth = maxDepth;
18985
18995
  }
18986
- const includeEntities = cleanBoolean(input.includeEntities);
18996
+ const includeEntities = cleanBoolean(effectiveInput.includeEntities);
18987
18997
  if (includeEntities !== void 0) {
18988
18998
  payload.includeEntities = includeEntities;
18989
18999
  }
18990
- const mode = cleanString4(input.mode);
19000
+ const mode = cleanString4(effectiveInput.mode);
18991
19001
  if (mode) {
18992
19002
  payload.mode = mode;
18993
19003
  }
18994
- const includeFailures = cleanBoolean(input.includeFailures);
19004
+ const includeFailures = cleanBoolean(effectiveInput.includeFailures);
18995
19005
  if (includeFailures !== void 0) {
18996
19006
  payload.includeFailures = includeFailures;
18997
19007
  }
18998
- const worktreeId = cleanString4(input.worktreeId);
19008
+ const worktreeId = cleanString4(effectiveInput.worktreeId);
18999
19009
  if (worktreeId) {
19000
19010
  payload.worktreeId = worktreeId;
19001
19011
  }
19002
- const sessionId = cleanString4(input.sessionId);
19012
+ const sessionId = cleanString4(effectiveInput.sessionId);
19003
19013
  if (sessionId) {
19004
19014
  payload.sessionId = sessionId;
19005
19015
  }
19006
- if (Array.isArray(input.packWeightOverrides) && input.packWeightOverrides.length > 0) {
19007
- payload.packWeightOverrides = input.packWeightOverrides;
19016
+ if (Array.isArray(effectiveInput.packWeightOverrides) && effectiveInput.packWeightOverrides.length > 0) {
19017
+ payload.packWeightOverrides = effectiveInput.packWeightOverrides;
19008
19018
  }
19009
19019
  return {
19010
19020
  path: "/api/platform/v1/context/compile",
@@ -19016,13 +19026,20 @@ function createContextClient(config = {}) {
19016
19026
  const gateway = createGatewayRequestClient(config);
19017
19027
  return {
19018
19028
  /**
19019
- * Compile a focused reasoning context pack for a topic scope.
19020
- * @param topicId - The topic to compile context for.
19029
+ * Compile a focused reasoning context pack.
19030
+ * @param topicIdOrInput - Optional topic ID, or compile input for query-first resolution.
19021
19031
  * @param input - Optional compile parameters (query, budget, ranking, etc.).
19022
19032
  * @returns The compiled context payload with beliefs, questions, and evidence.
19023
19033
  */
19024
- async compile(topicId, input = {}) {
19025
- const request = buildCompileContextRequest(topicId, input);
19034
+ async compile(topicIdOrInput = {}, input = {}) {
19035
+ const request = buildCompileContextRequest(topicIdOrInput, input);
19036
+ return gateway.request({
19037
+ ...request,
19038
+ body: request.body
19039
+ });
19040
+ },
19041
+ async compileByQuery(input = {}) {
19042
+ const request = buildCompileContextRequest(input);
19026
19043
  return gateway.request({
19027
19044
  ...request,
19028
19045
  body: request.body
@@ -21797,7 +21814,7 @@ function createToolRegistryClient(config = {}) {
21797
21814
  }
21798
21815
 
21799
21816
  // ../sdk/src/version.ts
21800
- var LUCERN_SDK_VERSION = "0.3.0-alpha.7";
21817
+ var LUCERN_SDK_VERSION = "0.3.0-alpha.8";
21801
21818
 
21802
21819
  // ../sdk/src/workflowClient.ts
21803
21820
  function normalizeLensQuery(value) {
@@ -23962,50 +23979,55 @@ function cleanNumber2(value) {
23962
23979
  function cleanBoolean2(value) {
23963
23980
  return typeof value === "boolean" ? value : void 0;
23964
23981
  }
23965
- function buildCompileContextRequest2(topicId, input = {}) {
23966
- const payload = { topicId };
23967
- const query5 = cleanString6(input.query);
23982
+ function buildCompileContextRequest2(topicIdOrInput = {}, input = {}) {
23983
+ const effectiveInput = typeof topicIdOrInput === "string" ? input : topicIdOrInput;
23984
+ const payload = {};
23985
+ const topicId = typeof topicIdOrInput === "string" ? cleanString6(topicIdOrInput) : cleanString6(effectiveInput.topicId);
23986
+ if (topicId) {
23987
+ payload.topicId = topicId;
23988
+ }
23989
+ const query5 = cleanString6(effectiveInput.query);
23968
23990
  if (query5) {
23969
23991
  payload.query = query5;
23970
23992
  }
23971
- const budget = cleanNumber2(input.budget) ?? cleanNumber2(input.tokenBudget);
23993
+ const budget = cleanNumber2(effectiveInput.budget) ?? cleanNumber2(effectiveInput.tokenBudget);
23972
23994
  if (budget !== void 0) {
23973
23995
  payload.budget = budget;
23974
23996
  }
23975
- const ranking = cleanString6(input.ranking) ?? cleanString6(input.rankingProfile);
23997
+ const ranking = cleanString6(effectiveInput.ranking) ?? cleanString6(effectiveInput.rankingProfile);
23976
23998
  if (ranking) {
23977
23999
  payload.ranking = ranking;
23978
24000
  }
23979
- const limit = cleanNumber2(input.limit);
24001
+ const limit = cleanNumber2(effectiveInput.limit);
23980
24002
  if (limit !== void 0) {
23981
24003
  payload.limit = limit;
23982
24004
  }
23983
- const maxDepth = cleanNumber2(input.maxDepth);
24005
+ const maxDepth = cleanNumber2(effectiveInput.maxDepth);
23984
24006
  if (maxDepth !== void 0) {
23985
24007
  payload.maxDepth = maxDepth;
23986
24008
  }
23987
- const includeEntities = cleanBoolean2(input.includeEntities);
24009
+ const includeEntities = cleanBoolean2(effectiveInput.includeEntities);
23988
24010
  if (includeEntities !== void 0) {
23989
24011
  payload.includeEntities = includeEntities;
23990
24012
  }
23991
- const mode = cleanString6(input.mode);
24013
+ const mode = cleanString6(effectiveInput.mode);
23992
24014
  if (mode) {
23993
24015
  payload.mode = mode;
23994
24016
  }
23995
- const includeFailures = cleanBoolean2(input.includeFailures);
24017
+ const includeFailures = cleanBoolean2(effectiveInput.includeFailures);
23996
24018
  if (includeFailures !== void 0) {
23997
24019
  payload.includeFailures = includeFailures;
23998
24020
  }
23999
- const worktreeId = cleanString6(input.worktreeId);
24021
+ const worktreeId = cleanString6(effectiveInput.worktreeId);
24000
24022
  if (worktreeId) {
24001
24023
  payload.worktreeId = worktreeId;
24002
24024
  }
24003
- const sessionId = cleanString6(input.sessionId);
24025
+ const sessionId = cleanString6(effectiveInput.sessionId);
24004
24026
  if (sessionId) {
24005
24027
  payload.sessionId = sessionId;
24006
24028
  }
24007
- if (Array.isArray(input.packWeightOverrides) && input.packWeightOverrides.length > 0) {
24008
- payload.packWeightOverrides = input.packWeightOverrides;
24029
+ if (Array.isArray(effectiveInput.packWeightOverrides) && effectiveInput.packWeightOverrides.length > 0) {
24030
+ payload.packWeightOverrides = effectiveInput.packWeightOverrides;
24009
24031
  }
24010
24032
  return {
24011
24033
  path: "/api/platform/v1/context/compile",
@@ -24015,8 +24037,12 @@ function buildCompileContextRequest2(topicId, input = {}) {
24015
24037
  }
24016
24038
  function createContextFacade(config) {
24017
24039
  return {
24018
- compile(topicId, input = {}) {
24019
- const request = buildCompileContextRequest2(topicId, input);
24040
+ compile(topicIdOrInput = {}, input = {}) {
24041
+ const request = buildCompileContextRequest2(topicIdOrInput, input);
24042
+ return config.transport.request(request);
24043
+ },
24044
+ compileByQuery(input = {}) {
24045
+ const request = buildCompileContextRequest2(input);
24020
24046
  return config.transport.request(request);
24021
24047
  }
24022
24048
  };
@@ -26665,24 +26691,27 @@ function readResultString(value, key) {
26665
26691
  }
26666
26692
  function createContextHandlers(context) {
26667
26693
  const compiler = createContextClient(context.sdkConfig);
26694
+ const functionSurface = createFunctionSurfaceClient(context.sdkConfig);
26668
26695
  return {
26669
26696
  compile_context: contractToHandler(
26670
26697
  MCP_TOOL_CONTRACTS.compile_context,
26671
26698
  async (params) => {
26672
- const topicId = readTopicId4(params, { required: true });
26673
- const response = await compiler.compile(
26674
- topicId,
26675
- {
26676
- ...readString3(params, "query") ? { query: readString3(params, "query") } : {},
26677
- ...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
26678
- ...readString3(params, "ranking") ? {
26679
- ranking: readString3(params, "ranking")
26680
- } : {},
26681
- ...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
26682
- ...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
26683
- ...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
26684
- }
26685
- );
26699
+ const topicId = readTopicId4(params);
26700
+ const query5 = readString3(params, "query");
26701
+ const input = {
26702
+ ...query5 ? { query: query5 } : {},
26703
+ ...readNumber2(params, "budget") !== void 0 ? { budget: readNumber2(params, "budget") } : {},
26704
+ ...readString3(params, "ranking") ? {
26705
+ ranking: readString3(params, "ranking")
26706
+ } : {},
26707
+ ...readNumber2(params, "limit") !== void 0 ? { limit: readNumber2(params, "limit") } : {},
26708
+ ...readNumber2(params, "maxDepth") !== void 0 ? { maxDepth: readNumber2(params, "maxDepth") } : {},
26709
+ ...readBoolean(params, "includeEntities") !== void 0 ? { includeEntities: readBoolean(params, "includeEntities") } : {}
26710
+ };
26711
+ if (!topicId && !query5) {
26712
+ throw new Error("[compile_context] query is required when topicId is omitted.");
26713
+ }
26714
+ const response = topicId ? await compiler.compile(topicId, input) : await functionSurface.compileContext(input);
26686
26715
  writeLocalLucernContext({
26687
26716
  topicId: readResultString(response.data, "topicId") ?? topicId,
26688
26717
  topicName: readResultString(response.data, "topicName"),
@@ -28530,7 +28559,7 @@ function createLucernStandaloneMcpServer(options) {
28530
28559
  });
28531
28560
  const server = new McpServer({
28532
28561
  name: "lucern-mcp",
28533
- version: "0.3.0-alpha.7"
28562
+ version: "0.3.0-alpha.8"
28534
28563
  });
28535
28564
  registerTools(server, runtime);
28536
28565
  const resources = registerResources(server, runtime, observationStore);