@cortexkit/magic-context 0.42.0 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +117 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16854,7 +16854,7 @@ function handleRefineResult(result, payload, input, inst) {
16854
16854
  payload.issues.push(issue(_iss));
16855
16855
  }
16856
16856
  }
16857
- var $ZodType, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, $ZodBase64, $ZodBase64URL, $ZodE164, $ZodJWT, $ZodNumber, $ZodNumberFormat, $ZodBoolean, $ZodUnknown, $ZodNever, $ZodArray, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodIntersection, $ZodTuple, $ZodRecord, $ZodEnum, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodReadonly, $ZodCustom;
16857
+ var $ZodType, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, $ZodBase64, $ZodBase64URL, $ZodE164, $ZodJWT, $ZodNumber, $ZodNumberFormat, $ZodBoolean, $ZodUnknown, $ZodNever, $ZodArray, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodIntersection, $ZodTuple, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodReadonly, $ZodCustom;
16858
16858
  var init_schemas = __esm(() => {
16859
16859
  init_checks();
16860
16860
  init_core();
@@ -17802,6 +17802,28 @@ var init_schemas = __esm(() => {
17802
17802
  return payload;
17803
17803
  };
17804
17804
  });
17805
+ $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
17806
+ $ZodType.init(inst, def);
17807
+ if (def.values.length === 0) {
17808
+ throw new Error("Cannot create literal schema with no valid values");
17809
+ }
17810
+ const values = new Set(def.values);
17811
+ inst._zod.values = values;
17812
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex2(o) : o ? escapeRegex2(o.toString()) : String(o)).join("|")})$`);
17813
+ inst._zod.parse = (payload, _ctx) => {
17814
+ const input = payload.value;
17815
+ if (values.has(input)) {
17816
+ return payload;
17817
+ }
17818
+ payload.issues.push({
17819
+ code: "invalid_value",
17820
+ values: def.values,
17821
+ input,
17822
+ inst
17823
+ });
17824
+ return payload;
17825
+ };
17826
+ });
17805
17827
  $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
17806
17828
  $ZodType.init(inst, def);
17807
17829
  inst._zod.optin = "optional";
@@ -19075,6 +19097,43 @@ var formatMap, stringProcessor = (schema, ctx, _json, _params) => {
19075
19097
  if (values.every((v) => typeof v === "string"))
19076
19098
  json.type = "string";
19077
19099
  json.enum = values;
19100
+ }, literalProcessor = (schema, ctx, json, _params) => {
19101
+ const def = schema._zod.def;
19102
+ const vals = [];
19103
+ for (const val of def.values) {
19104
+ if (val === undefined) {
19105
+ if (ctx.unrepresentable === "throw") {
19106
+ throw new Error("Literal `undefined` cannot be represented in JSON Schema");
19107
+ }
19108
+ } else if (typeof val === "bigint") {
19109
+ if (ctx.unrepresentable === "throw") {
19110
+ throw new Error("BigInt literals cannot be represented in JSON Schema");
19111
+ } else {
19112
+ vals.push(Number(val));
19113
+ }
19114
+ } else {
19115
+ vals.push(val);
19116
+ }
19117
+ }
19118
+ if (vals.length === 0) {} else if (vals.length === 1) {
19119
+ const val = vals[0];
19120
+ json.type = val === null ? "null" : typeof val;
19121
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
19122
+ json.enum = [val];
19123
+ } else {
19124
+ json.const = val;
19125
+ }
19126
+ } else {
19127
+ if (vals.every((v) => typeof v === "number"))
19128
+ json.type = "number";
19129
+ if (vals.every((v) => typeof v === "string"))
19130
+ json.type = "string";
19131
+ if (vals.every((v) => typeof v === "boolean"))
19132
+ json.type = "boolean";
19133
+ if (vals.every((v) => v === null))
19134
+ json.type = "null";
19135
+ json.enum = vals;
19136
+ }
19078
19137
  }, customProcessor = (_schema, ctx, _json, _params) => {
19079
19138
  if (ctx.unrepresentable === "throw") {
19080
19139
  throw new Error("Custom types cannot be represented in JSON Schema");
@@ -19539,6 +19598,13 @@ function _enum(values, params) {
19539
19598
  ...normalizeParams(params)
19540
19599
  });
19541
19600
  }
19601
+ function literal(value, params) {
19602
+ return new ZodLiteral({
19603
+ type: "literal",
19604
+ values: Array.isArray(value) ? value : [value],
19605
+ ...normalizeParams(params)
19606
+ });
19607
+ }
19542
19608
  function transform(fn) {
19543
19609
  return new ZodTransform({
19544
19610
  type: "transform",
@@ -19614,7 +19680,7 @@ function refine(fn, _params = {}) {
19614
19680
  function superRefine(fn, params) {
19615
19681
  return _superRefine(fn, params);
19616
19682
  }
19617
- var _installedGroups, ZodType, _ZodString, ZodString, ZodStringFormat, ZodEmail, ZodGUID, ZodUUID, ZodURL, ZodEmoji, ZodNanoID, ZodCUID, ZodCUID2, ZodULID, ZodXID, ZodKSUID, ZodIPv4, ZodIPv6, ZodCIDRv4, ZodCIDRv6, ZodBase64, ZodBase64URL, ZodE164, ZodJWT, ZodNumber, ZodNumberFormat, ZodBoolean, ZodUnknown, ZodNever, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodEnum, ZodTransform, ZodOptional, ZodExactOptional, ZodNullable, ZodDefault, ZodPrefault, ZodNonOptional, ZodCatch, ZodPipe, ZodReadonly, ZodCustom;
19683
+ var _installedGroups, ZodType, _ZodString, ZodString, ZodStringFormat, ZodEmail, ZodGUID, ZodUUID, ZodURL, ZodEmoji, ZodNanoID, ZodCUID, ZodCUID2, ZodULID, ZodXID, ZodKSUID, ZodIPv4, ZodIPv6, ZodCIDRv4, ZodCIDRv6, ZodBase64, ZodBase64URL, ZodE164, ZodJWT, ZodNumber, ZodNumberFormat, ZodBoolean, ZodUnknown, ZodNever, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodEnum, ZodLiteral, ZodTransform, ZodOptional, ZodExactOptional, ZodNullable, ZodDefault, ZodPrefault, ZodNonOptional, ZodCatch, ZodPipe, ZodReadonly, ZodCustom;
19618
19684
  var init_schemas2 = __esm(() => {
19619
19685
  init_core2();
19620
19686
  init_core2();
@@ -20134,6 +20200,20 @@ var init_schemas2 = __esm(() => {
20134
20200
  });
20135
20201
  };
20136
20202
  });
20203
+ ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
20204
+ $ZodLiteral.init(inst, def);
20205
+ ZodType.init(inst, def);
20206
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
20207
+ inst.values = new Set(def.values);
20208
+ Object.defineProperty(inst, "value", {
20209
+ get() {
20210
+ if (def.values.length > 1) {
20211
+ throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
20212
+ }
20213
+ return def.values[0];
20214
+ }
20215
+ });
20216
+ });
20137
20217
  ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
20138
20218
  $ZodTransform.init(inst, def);
20139
20219
  ZodType.init(inst, def);
@@ -20619,6 +20699,8 @@ var init_magic_context = __esm(() => {
20619
20699
  api_key: string2().optional().describe("API key for remote embedding provider (optional)"),
20620
20700
  input_type: string2().optional().describe("Default input_type for stored/indexed (passage) embeddings in the request body. Required by some openai-compatible providers (e.g. NVIDIA NIM). Omitted from the request when unset."),
20621
20701
  query_input_type: string2().optional().describe("Optional input_type for query (search) embeddings on asymmetric models (e.g. NVIDIA NIM 'query'). When unset, query embeddings use embedding.input_type. Passage/stored content always uses embedding.input_type."),
20702
+ query_instruction: union([string2(), literal(false)]).optional().describe("OpenAI-compatible query prefix override. A string is prepended verbatim to search queries; false disables the built-in model-family instruction. Qwen3-Embedding, gte-Qwen instruct, e5 instruct, and Nomic families have built-in recipes. Query-only changes do not re-embed stored content. User-level only; project values are ignored."),
20703
+ document_prefix: string2().optional().describe("OpenAI-compatible stored-document prefix override, prepended verbatim. Defaults to the model-family recipe (empty for Qwen3/gte/e5 instruct; 'search_document: ' for Nomic). Changing it changes stored vectors and triggers re-embedding. User-level only; project values are ignored."),
20622
20704
  truncate: string2().optional().describe("Optional truncate mode sent in the embedding request body (e.g. NVIDIA NIM accepts 'NONE' | 'START' | 'END'). Omitted from the request when unset."),
20623
20705
  max_input_tokens: number2().int().positive().optional().describe("Optional maximum input tokens for chunk embeddings. Defaults conservatively to 512 when omitted."),
20624
20706
  local_runtime: _enum(["auto", "native", "wasm"]).default("auto").describe("Local provider only: ONNX runtime selection. 'auto' uses native under Node and uses WASM under Bun versions before 1.4.0, where Bun's NAPI teardown race can panic on quit; native is restored automatically on Bun 1.4.0+. Set 'native' only to prefer speed while accepting that pre-1.4.0 Bun crash risk, or 'wasm' to avoid loading the native addon."),
@@ -20670,6 +20752,8 @@ var init_magic_context = __esm(() => {
20670
20752
  ...apiKey ? { api_key: apiKey } : {},
20671
20753
  ...inputType ? { input_type: inputType } : {},
20672
20754
  ...queryInputType ? { query_input_type: queryInputType } : {},
20755
+ ...data.query_instruction !== undefined ? { query_instruction: data.query_instruction } : {},
20756
+ ...data.document_prefix !== undefined ? { document_prefix: data.document_prefix } : {},
20673
20757
  ...truncate ? { truncate } : {},
20674
20758
  ...data.max_input_tokens ? { max_input_tokens: data.max_input_tokens } : {}
20675
20759
  };
@@ -20695,6 +20779,8 @@ var init_magic_context = __esm(() => {
20695
20779
  ...apiKey ? { api_key: apiKey } : {},
20696
20780
  ...inputType ? { input_type: inputType } : {},
20697
20781
  ...queryInputType ? { query_input_type: queryInputType } : {},
20782
+ ...data.query_instruction !== undefined ? { query_instruction: data.query_instruction } : {},
20783
+ ...data.document_prefix !== undefined ? { document_prefix: data.document_prefix } : {},
20698
20784
  ...truncate ? { truncate } : {},
20699
20785
  ...data.max_input_tokens ? { max_input_tokens: data.max_input_tokens } : {}
20700
20786
  };
@@ -21109,14 +21195,14 @@ function stripUnsafeProjectConfigFields(projectRaw) {
21109
21195
  const embedding = projectRaw.embedding;
21110
21196
  if (isPlainObject3(embedding)) {
21111
21197
  const removed = [];
21112
- for (const field of EMBEDDING_DESTINATION_FIELDS) {
21198
+ for (const field of EMBEDDING_USER_ONLY_FIELDS) {
21113
21199
  if (field in embedding) {
21114
21200
  delete embedding[field];
21115
21201
  removed.push(field);
21116
21202
  }
21117
21203
  }
21118
21204
  if (removed.length > 0) {
21119
- warnings.push(`Ignoring embedding.${removed.join("/")} from project config ` + "(security: a repository cannot choose where private text is embedded).");
21205
+ warnings.push(`Ignoring embedding.${removed.join("/")} from project config ` + "(security: a repository cannot choose where or how private text is embedded).");
21120
21206
  }
21121
21207
  }
21122
21208
  for (const agentKey of HIDDEN_AGENT_KEYS) {
@@ -21351,7 +21437,7 @@ function dropInheritedEmbeddingKeyOnRedirect(projectRaw, mergedRaw, userRaw) {
21351
21437
  "Dropped inherited user embedding api_key because project config redirected " + "embedding.endpoint without supplying its own key (security: prevents key " + "exfiltration to a repository-chosen endpoint)."
21352
21438
  ];
21353
21439
  }
21354
- var HIDDEN_AGENT_KEYS, HARNESS_KEYS, HISTORIAN_USER_ONLY_FIELDS, PROMPT_SURFACE_USER_ONLY_FIELDS, AGENT_ESCALATION_FIELDS, EMBEDDING_DESTINATION_FIELDS, PERCENTAGE_THRESHOLD_REASON = "security: a repository may only raise compaction thresholds above the user's effective value; it cannot force earlier historian work or cloned-repo cost escalation.", TOKEN_THRESHOLD_REASON = "security: a repository may only raise execute_threshold_tokens above the user's trusted token threshold; it cannot force earlier historian work or cloned-repo cost escalation.", TOKEN_THRESHOLD_INTRODUCTION_REASON = "security: a repository cannot introduce a new execute_threshold_tokens override when the user has no trusted token threshold for that key; that could force earlier historian work or cloned-repo cost escalation.", PROTECTED_TOKENS_REASON = "security: a repository may only raise protected_tokens above the resolved user-or-derived floor; it cannot lower protection.", PROTECTED_TOKENS_TIER_OVERRIDES;
21440
+ var HIDDEN_AGENT_KEYS, HARNESS_KEYS, HISTORIAN_USER_ONLY_FIELDS, PROMPT_SURFACE_USER_ONLY_FIELDS, AGENT_ESCALATION_FIELDS, EMBEDDING_USER_ONLY_FIELDS, PERCENTAGE_THRESHOLD_REASON = "security: a repository may only raise compaction thresholds above the user's effective value; it cannot force earlier historian work or cloned-repo cost escalation.", TOKEN_THRESHOLD_REASON = "security: a repository may only raise execute_threshold_tokens above the user's trusted token threshold; it cannot force earlier historian work or cloned-repo cost escalation.", TOKEN_THRESHOLD_INTRODUCTION_REASON = "security: a repository cannot introduce a new execute_threshold_tokens override when the user has no trusted token threshold for that key; that could force earlier historian work or cloned-repo cost escalation.", PROTECTED_TOKENS_REASON = "security: a repository may only raise protected_tokens above the resolved user-or-derived floor; it cannot lower protection.", PROTECTED_TOKENS_TIER_OVERRIDES;
21355
21441
  var init_project_security = __esm(() => {
21356
21442
  init_magic_context();
21357
21443
  HIDDEN_AGENT_KEYS = ["historian", "dreamer"];
@@ -21359,7 +21445,13 @@ var init_project_security = __esm(() => {
21359
21445
  HISTORIAN_USER_ONLY_FIELDS = PER_HARNESS_MIGRATION_INVENTORY.historian.migrated_execution;
21360
21446
  PROMPT_SURFACE_USER_ONLY_FIELDS = ["guidance_override_path", "tool_descriptions"];
21361
21447
  AGENT_ESCALATION_FIELDS = ["prompt", "permission", "tools"];
21362
- EMBEDDING_DESTINATION_FIELDS = ["endpoint", "provider", "fallback_provider"];
21448
+ EMBEDDING_USER_ONLY_FIELDS = [
21449
+ "endpoint",
21450
+ "provider",
21451
+ "fallback_provider",
21452
+ "query_instruction",
21453
+ "document_prefix"
21454
+ ];
21363
21455
  PROTECTED_TOKENS_TIER_OVERRIDES = Symbol.for("@cortexkit/magic-context/protected-tokens-tier-overrides");
21364
21456
  });
21365
21457
 
@@ -35631,7 +35723,8 @@ function getSynapseBatchRequestKey(args) {
35631
35723
  allow_equivalent: false,
35632
35724
  accept_declared: false,
35633
35725
  ids: args.items.map((item) => item.id),
35634
- content_sha256: args.items.map((item) => item.contentSha256)
35726
+ content_sha256: args.items.map((item) => item.contentSha256),
35727
+ ...args.purpose === "query" ? { purpose: args.purpose } : {}
35635
35728
  }));
35636
35729
  }
35637
35730
  function hashContent(text) {
@@ -35888,7 +35981,7 @@ class SynapseEmbeddingProvider {
35888
35981
  })();
35889
35982
  return this.initializing;
35890
35983
  }
35891
- async embed(text, signal) {
35984
+ async embed(text, signal, purpose = "passage") {
35892
35985
  if (!await this.initialize() || signal?.aborted || !this.metadata)
35893
35986
  return null;
35894
35987
  if (estimateTokens(text) > this.metadata.max_tokens)
@@ -35898,6 +35991,7 @@ class SynapseEmbeddingProvider {
35898
35991
  const value = await this.callWithRetry("embed.query", this.requestConstraints({
35899
35992
  id,
35900
35993
  text,
35994
+ purpose,
35901
35995
  deadline_ms: this.options.queryTimeoutMs ?? SYNAPSE_DEFAULT_QUERY_TIMEOUT_MS
35902
35996
  }), this.options.queryTimeoutMs ?? SYNAPSE_DEFAULT_QUERY_TIMEOUT_MS, true, signal);
35903
35997
  const extracted = extractVector(value);
@@ -35917,7 +36011,7 @@ class SynapseEmbeddingProvider {
35917
36011
  return null;
35918
36012
  }
35919
36013
  }
35920
- async embedBatch(texts, signal) {
36014
+ async embedBatch(texts, signal, purpose = "passage") {
35921
36015
  if (texts.length === 0)
35922
36016
  return [];
35923
36017
  const items = texts.map((text, index) => ({
@@ -35925,10 +36019,10 @@ class SynapseEmbeddingProvider {
35925
36019
  text,
35926
36020
  contentSha256: hashContent(text)
35927
36021
  }));
35928
- const map = await this.embedItems(items, signal);
36022
+ const map = await this.embedItems(items, signal, purpose);
35929
36023
  return items.map((item) => map.get(item.id) ?? null);
35930
36024
  }
35931
- async embedItems(items, signal) {
36025
+ async embedItems(items, signal, purpose = "passage") {
35932
36026
  const output = new Map;
35933
36027
  if (items.length === 0 || !await this.initialize() || !this.metadata || signal?.aborted) {
35934
36028
  return output;
@@ -35941,12 +36035,12 @@ class SynapseEmbeddingProvider {
35941
36035
  const page = this.nextPage(eligibleItems, start);
35942
36036
  start += page.length;
35943
36037
  try {
35944
- const requestKey = this.requestKey(page);
36038
+ const requestKey = this.requestKey(page, purpose);
35945
36039
  let body = {};
35946
36040
  let restarted = false;
35947
36041
  for (;; ) {
35948
36042
  try {
35949
- body = await this.callWithRetry("embed.batch", this.batchRequest(page, requestKey), this.options.batchTimeoutMs ?? SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS, true, signal);
36043
+ body = await this.callWithRetry("embed.batch", this.batchRequest(page, requestKey, purpose), this.options.batchTimeoutMs ?? SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS, true, signal);
35950
36044
  const first = responseBody(body);
35951
36045
  const jobId = typeof first.job_id === "string" ? first.job_id : null;
35952
36046
  if (jobId)
@@ -36016,24 +36110,26 @@ class SynapseEmbeddingProvider {
36016
36110
  accept_declared: false
36017
36111
  };
36018
36112
  }
36019
- batchRequest(items, requestKey) {
36113
+ batchRequest(items, requestKey, purpose) {
36020
36114
  return this.requestConstraints({
36021
36115
  items: items.map((item) => ({
36022
36116
  id: item.id,
36023
36117
  text: item.text,
36024
36118
  content_sha256: item.contentSha256
36025
36119
  })),
36026
- request_key: requestKey
36120
+ request_key: requestKey,
36121
+ purpose
36027
36122
  });
36028
36123
  }
36029
- requestKey(items) {
36124
+ requestKey(items, purpose) {
36030
36125
  if (!this.metadata)
36031
36126
  throw new SynapseEmbeddingError("transport", "Synapse metadata is unavailable");
36032
36127
  return getSynapseBatchRequestKey({
36033
36128
  model: this.metadata.model,
36034
36129
  fingerprint: this.metadata.fingerprint,
36035
36130
  tableEpoch: this.metadata.table_epoch,
36036
- items
36131
+ items,
36132
+ purpose
36037
36133
  });
36038
36134
  }
36039
36135
  async pollBatch(jobId, requestKey, signal) {
@@ -36937,12 +37033,16 @@ var init_diagnostics_opencode = __esm(() => {
36937
37033
  init_redaction2();
36938
37034
  import_comment_json9 = __toESM(require_src3(), 1);
36939
37035
  });
37036
+ // ../plugin/src/features/magic-context/memory/embedding-model-match.ts
37037
+ var init_embedding_model_match = () => {};
37038
+
36940
37039
  // ../plugin/src/features/magic-context/memory/normalize-hash.ts
36941
37040
  var init_normalize_hash = () => {};
36942
37041
 
36943
37042
  // ../plugin/src/features/magic-context/memory/embedding-identity.ts
36944
37043
  var init_embedding_identity = __esm(() => {
36945
37044
  init_magic_context();
37045
+ init_embedding_model_match();
36946
37046
  init_embedding_synapse();
36947
37047
  init_normalize_hash();
36948
37048
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode, Pi, and OMP",
5
5
  "keywords": [
6
6
  "opencode",