@loreai/core 0.14.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  /**
2
- * Dynamic worker model selection.
2
+ * Worker model resolution.
3
3
  *
4
- * Background workers (distillation, curation, query expansion) don't need
5
- * frontier reasoning. This module discovers cheaper models from the same
6
- * provider and validates their quality via a two-phase comparison:
7
- * Phase 1: structural checks (parsability, observation count, token bounds)
8
- * Phase 2: LLM judge (session model rates candidate output vs reference)
4
+ * Background workers (distillation, curation, query expansion) use the session
5
+ * model by default. An explicit `workerModel` config override is supported for
6
+ * cases where the user wants to pin background work to a specific model.
9
7
  *
10
- * Results are persisted in kv_meta and re-evaluated when the model landscape
11
- * changes (new models, session model switch, model deprecation).
8
+ * Previously this module contained dynamic worker model selection with
9
+ * candidate discovery, two-phase validation (structural check + LLM judge),
10
+ * and fingerprint-based staleness detection. That complexity was removed in
11
+ * favor of always using the session model — A/B testing showed the quality
12
+ * gap on complex conversations wasn't worth the infrastructure cost.
12
13
  */
13
- /** Minimal model info needed for worker selection — provider-agnostic. */
14
+ /** Minimal model info kept for downstream consumers. */
14
15
  export type ModelInfo = {
15
16
  id: string;
16
17
  providerID: string;
@@ -26,80 +27,11 @@ export type ModelInfo = {
26
27
  reasoning?: boolean;
27
28
  };
28
29
  };
29
- /** Result of a worker model validation stored in kv_meta. */
30
- export type WorkerModelResult = {
31
- modelID: string;
32
- providerID: string;
33
- fingerprint: string;
34
- validatedAt: number;
35
- judgeScore: number | null;
36
- };
37
- /**
38
- * Select worker model candidates from the available models.
39
- *
40
- * Returns up to 2 candidates: cheapest overall + one tier below the session
41
- * model. The session model itself is included (if it's the cheapest, the list
42
- * has 1 entry and no comparison is needed).
43
- */
44
- export declare function selectWorkerCandidates(sessionModel: {
45
- id: string;
46
- providerID: string;
47
- cost: {
48
- input: number;
49
- };
50
- }, providerModels: ModelInfo[]): ModelInfo[];
51
- /**
52
- * Compute a fingerprint from the model landscape. Changes when:
53
- * - Models are added or removed from the provider
54
- * - The session model changes
55
- */
56
- export declare function computeModelFingerprint(providerID: string, sessionModelID: string, activeModelIDs: string[]): string;
57
- export declare function getValidatedWorkerModel(providerID: string): WorkerModelResult | null;
58
- export declare function storeValidatedWorkerModel(result: WorkerModelResult): void;
59
- /** Clear a stored worker model validation (e.g. when the model is deprecated). */
60
- export declare function clearValidatedWorkerModel(providerID: string): void;
61
- /**
62
- * Check whether the stored validation is stale (fingerprint mismatch).
63
- */
64
- export declare function isValidationStale(stored: WorkerModelResult | null, currentFingerprint: string): boolean;
65
- export type StructuralCheckResult = {
66
- passed: boolean;
67
- observationCount: number;
68
- tokenCount: number;
69
- reason?: string;
70
- };
71
- /**
72
- * Structural quality check: does the candidate distillation output meet
73
- * minimum quality thresholds relative to the reference?
74
- */
75
- export declare function structuralCheck(candidateObservations: string | null, referenceObservations: string): StructuralCheckResult;
76
- export declare const WORKER_JUDGE_SYSTEM = "You are evaluating distillation quality. You will be given a REFERENCE distillation (produced by a capable model) and a CANDIDATE distillation (produced by a cheaper model) of the same conversation segment.\n\nRate the candidate on a scale of 1-5:\n5 = Captures all key facts and decisions, equivalent to reference\n4 = Captures most facts, minor omissions\n3 = Captures the essential facts, some detail loss acceptable\n2 = Missing important facts or technical details\n1 = Significantly incomplete or inaccurate\n\nRespond with ONLY a single digit (1-5).";
77
- export declare function workerJudgeUser(reference: string, candidate: string): string;
78
- /** Parse the judge's score from a response. Returns null on parse failure. */
79
- export declare function parseJudgeScore(response: string): number | null;
80
- import type { LLMClient } from "./types";
81
- export type ValidationInput = {
82
- llm: LLMClient;
83
- providerID: string;
84
- sessionModelID: string;
85
- candidates: ModelInfo[];
86
- /** Recent gen-0 distillation to use as reference (observations text). */
87
- referenceObservations: string;
88
- /** Source messages text for re-running distillation with candidates. */
89
- sourceMessagesText: string;
90
- /** Date string for the distillation prompt. */
91
- date: string;
92
- };
93
- /**
94
- * Run the two-phase quality validation for worker model candidates.
95
- * Returns the cheapest passing candidate, or null if none pass.
96
- */
97
- export declare function runValidation(input: ValidationInput): Promise<WorkerModelResult | null>;
98
30
  /**
99
31
  * Resolve the effective worker model for a given provider.
100
- * Priority: explicit config > validated auto-selection > session model (fallback).
32
+ * Priority: explicit config override > session model (fallback).
101
33
  */
102
- export declare function resolveWorkerModel(providerID: string, configWorkerModel?: {
34
+ export declare function resolveWorkerModel(_providerID: string, configWorkerModel?: {
103
35
  providerID: string;
104
36
  modelID: string;
105
37
  }, configModel?: {
@@ -1 +1 @@
1
- {"version":3,"file":"worker-model.d.ts","sourceRoot":"","sources":["../../src/worker-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE;QACZ,KAAK,EAAE;YAAE,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC;QACzB,+DAA+D;QAC/D,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,6DAA6D;AAC7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAQF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACzE,cAAc,EAAE,SAAS,EAAE,GAC1B,SA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E,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAMrD"}
package/dist/node/db.d.ts CHANGED
@@ -19,4 +19,15 @@ export declare function loadForceMinLayer(sessionID: string): number;
19
19
  * (consumed) to avoid unbounded growth.
20
20
  */
21
21
  export declare function saveForceMinLayer(sessionID: string, layer: number): void;
22
+ /** Get a metadata value by key. Returns null if not found. */
23
+ export declare function getMeta(key: string): string | null;
24
+ /** Set a metadata value (upsert). */
25
+ export declare function setMeta(key: string, value: string): void;
26
+ /**
27
+ * Get or create the installation instance ID.
28
+ *
29
+ * Generated once (UUID v4) on first call, then persisted in the metadata
30
+ * table across process restarts and upgrades.
31
+ */
32
+ export declare function getInstanceId(): string;
22
33
  //# sourceMappingURL=db.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA0WtC,wBAAgB,EAAE,IAAI,QAAQ,CAkC7B;AAmGD,wBAAgB,KAAK,SAKpB;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1D;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAYxE"}
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAsXtC,wBAAgB,EAAE,IAAI,QAAQ,CAkC7B;AAwGD,wBAAgB,KAAK,SAKpB;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1D;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAYxE;AAMD,8DAA8D;AAC9D,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKlD;AAED,qCAAqC;AACrC,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAMxD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAMtC"}
@@ -10,7 +10,7 @@ export { runRecall, RECALL_TOOL_DESCRIPTION, RECALL_PARAM_DESCRIPTIONS, type Rec
10
10
  export type { LoreMessage, LoreUserMessage, LoreAssistantMessage, LorePart, LoreTextPart, LoreReasoningPart, LoreToolPart, LoreGenericPart, LoreToolState, LoreToolStatePending, LoreToolStateRunning, LoreToolStateCompleted, LoreToolStateError, LoreMessageWithParts, LLMClient, } from "./types";
11
11
  export { isTextPart, isReasoningPart, isToolPart } from "./types";
12
12
  export { load, config, type LoreConfig } from "./config";
13
- export { db, ensureProject, isFirstRun, projectId, projectName, loadForceMinLayer, saveForceMinLayer, close, } from "./db";
13
+ export { db, ensureProject, isFirstRun, projectId, projectName, loadForceMinLayer, saveForceMinLayer, getMeta, setMeta, getInstanceId, close, } from "./db";
14
14
  export { transform, setModelLimits, setMaxLayer0Tokens, computeLayer0Cap, needsUrgentDistillation, calibrate, setLtmTokens, getLtmTokens, getLtmBudget, setForceMinLayer, getLastTransformedCount, getLastTransformEstimate, toolStripAnnotation, onIdleResume, getLastTurnAt, consumeCameOutOfIdle, setLastTurnAtForTest, inspectSessionState, } from "./gradient";
15
15
  export { formatKnowledge, formatDistillations, DISTILLATION_SYSTEM, distillationUser, RECURSIVE_SYSTEM, recursiveUser, CURATOR_SYSTEM, curatorUser, CONSOLIDATION_SYSTEM, consolidationUser, QUERY_EXPANSION_SYSTEM, COMPACT_SUMMARY_TEMPLATE, buildCompactPrompt, } from "./prompt";
16
16
  export { shouldImport, importFromFile, exportToFile, exportLoreFile, importLoreFile, shouldImportLoreFile, loreFileExists, LORE_FILE, } from "./agents-file";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB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AAY,CAAC"}
@@ -508,6 +508,18 @@ var MIGRATIONS = [
508
508
  -- Both columns are nullable REALs \u2014 cheap to add, no backfill needed.
509
509
  ALTER TABLE distillations ADD COLUMN r_compression REAL;
510
510
  ALTER TABLE distillations ADD COLUMN c_norm REAL;
511
+ `,
512
+ `
513
+ -- Version 13: Installation metadata table for telemetry and diagnostics.
514
+ --
515
+ -- Separate from kv_meta (plugin state) \u2014 this holds installation-scoped
516
+ -- values: instance_id, release_channel, etc. Has updated_at for tracking
517
+ -- when values last changed.
518
+ CREATE TABLE IF NOT EXISTS metadata (
519
+ key TEXT PRIMARY KEY,
520
+ value TEXT NOT NULL,
521
+ updated_at INTEGER NOT NULL
522
+ );
511
523
  `
512
524
  ];
513
525
  function dataDir() {
@@ -583,6 +595,11 @@ function recoverMissingObjects(database) {
583
595
  key TEXT PRIMARY KEY,
584
596
  value TEXT NOT NULL
585
597
  );
598
+ CREATE TABLE IF NOT EXISTS metadata (
599
+ key TEXT PRIMARY KEY,
600
+ value TEXT NOT NULL,
601
+ updated_at INTEGER NOT NULL
602
+ );
586
603
  `);
587
604
  }
588
605
  function close() {
@@ -625,6 +642,22 @@ function saveForceMinLayer(sessionID, layer) {
625
642
  ).run(sessionID, layer, Date.now());
626
643
  }
627
644
  }
645
+ function getMeta(key) {
646
+ const row = db().query("SELECT value FROM metadata WHERE key = ?").get(key);
647
+ return row?.value ?? null;
648
+ }
649
+ function setMeta(key, value) {
650
+ db().query(
651
+ "INSERT INTO metadata (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = ?, updated_at = ?"
652
+ ).run(key, value, Date.now(), value, Date.now());
653
+ }
654
+ function getInstanceId() {
655
+ const existing = getMeta("instance_id");
656
+ if (existing) return existing;
657
+ const id = crypto.randomUUID();
658
+ setMeta("instance_id", id);
659
+ return id;
660
+ }
628
661
 
629
662
  // ../../node_modules/.bun/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
630
663
  var emptyOptions = {};
@@ -28972,208 +29005,10 @@ function importLoreFile(projectPath) {
28972
29005
  // src/worker-model.ts
28973
29006
  var worker_model_exports = {};
28974
29007
  __export(worker_model_exports, {
28975
- WORKER_JUDGE_SYSTEM: () => WORKER_JUDGE_SYSTEM,
28976
- clearValidatedWorkerModel: () => clearValidatedWorkerModel,
28977
- computeModelFingerprint: () => computeModelFingerprint,
28978
- getValidatedWorkerModel: () => getValidatedWorkerModel,
28979
- isValidationStale: () => isValidationStale,
28980
- parseJudgeScore: () => parseJudgeScore,
28981
- resolveWorkerModel: () => resolveWorkerModel,
28982
- runValidation: () => runValidation,
28983
- selectWorkerCandidates: () => selectWorkerCandidates,
28984
- storeValidatedWorkerModel: () => storeValidatedWorkerModel,
28985
- structuralCheck: () => structuralCheck,
28986
- workerJudgeUser: () => workerJudgeUser
29008
+ resolveWorkerModel: () => resolveWorkerModel
28987
29009
  });
28988
- var KV_PREFIX = "lore:worker_model:";
28989
- function selectWorkerCandidates(sessionModel, providerModels) {
28990
- const eligible = providerModels.filter(
28991
- (m) => m.providerID === sessionModel.providerID && m.status === "active" && m.capabilities.input.text
28992
- );
28993
- if (eligible.length === 0) return [];
28994
- const sorted = [...eligible].sort((a, b) => {
28995
- const costDiff = a.cost.input - b.cost.input;
28996
- if (costDiff !== 0) return costDiff;
28997
- const aReasoning = a.capabilities.reasoning ? 1 : 0;
28998
- const bReasoning = b.capabilities.reasoning ? 1 : 0;
28999
- return aReasoning - bReasoning;
29000
- });
29001
- const cheapest = sorted[0];
29002
- const belowSession = sorted.filter((m) => m.cost.input < sessionModel.cost.input).pop();
29003
- const candidates = /* @__PURE__ */ new Map();
29004
- candidates.set(cheapest.id, cheapest);
29005
- if (belowSession && belowSession.id !== cheapest.id) {
29006
- candidates.set(belowSession.id, belowSession);
29007
- }
29008
- if (cheapest.id === sessionModel.id || cheapest.cost.input >= sessionModel.cost.input) {
29009
- return [cheapest];
29010
- }
29011
- return [...candidates.values()];
29012
- }
29013
- function computeModelFingerprint(providerID, sessionModelID, activeModelIDs) {
29014
- const sorted = [...activeModelIDs].sort();
29015
- return sha256(
29016
- JSON.stringify({ providerID, sessionModelID, modelIDs: sorted })
29017
- );
29018
- }
29019
- function getValidatedWorkerModel(providerID) {
29020
- const row = db().query("SELECT value FROM kv_meta WHERE key = ?").get(`${KV_PREFIX}${providerID}`);
29021
- if (!row) return null;
29022
- try {
29023
- return JSON.parse(row.value);
29024
- } catch {
29025
- return null;
29026
- }
29027
- }
29028
- function storeValidatedWorkerModel(result) {
29029
- const key = `${KV_PREFIX}${result.providerID}`;
29030
- const value = JSON.stringify(result);
29031
- db().query(
29032
- "INSERT INTO kv_meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = ?"
29033
- ).run(key, value, value);
29034
- }
29035
- function clearValidatedWorkerModel(providerID) {
29036
- db().query("DELETE FROM kv_meta WHERE key = ?").run(`${KV_PREFIX}${providerID}`);
29037
- }
29038
- function isValidationStale(stored, currentFingerprint) {
29039
- if (!stored) return true;
29040
- return stored.fingerprint !== currentFingerprint;
29041
- }
29042
- function structuralCheck(candidateObservations, referenceObservations) {
29043
- if (candidateObservations == null || candidateObservations.length === 0) {
29044
- return { passed: false, observationCount: 0, tokenCount: 0, reason: candidateObservations === null ? "parse_failed" : "empty" };
29045
- }
29046
- const countObs = (text4) => text4.split("\n").filter((l) => l.trim().length > 0).length;
29047
- const refCount = countObs(referenceObservations);
29048
- const candCount = countObs(candidateObservations);
29049
- const candTokens = Math.ceil(candidateObservations.length / 3);
29050
- if (refCount > 0 && (candCount < refCount * 0.5 || candCount > refCount * 1.5)) {
29051
- return {
29052
- passed: false,
29053
- observationCount: candCount,
29054
- tokenCount: candTokens,
29055
- reason: `observation_count_${candCount}_vs_ref_${refCount}`
29056
- };
29057
- }
29058
- const refTokens = Math.ceil(referenceObservations.length / 3);
29059
- if (candTokens === 0) {
29060
- return { passed: false, observationCount: candCount, tokenCount: candTokens, reason: "empty" };
29061
- }
29062
- if (refTokens > 0 && candTokens > refTokens * 3) {
29063
- return {
29064
- passed: false,
29065
- observationCount: candCount,
29066
- tokenCount: candTokens,
29067
- reason: `token_count_${candTokens}_vs_ref_${refTokens}_3x`
29068
- };
29069
- }
29070
- return { passed: true, observationCount: candCount, tokenCount: candTokens };
29071
- }
29072
- var WORKER_JUDGE_SYSTEM = `You are evaluating distillation quality. You will be given a REFERENCE distillation (produced by a capable model) and a CANDIDATE distillation (produced by a cheaper model) of the same conversation segment.
29073
-
29074
- Rate the candidate on a scale of 1-5:
29075
- 5 = Captures all key facts and decisions, equivalent to reference
29076
- 4 = Captures most facts, minor omissions
29077
- 3 = Captures the essential facts, some detail loss acceptable
29078
- 2 = Missing important facts or technical details
29079
- 1 = Significantly incomplete or inaccurate
29080
-
29081
- Respond with ONLY a single digit (1-5).`;
29082
- function workerJudgeUser(reference, candidate) {
29083
- return `<reference>
29084
- ${reference}
29085
- </reference>
29086
-
29087
- <candidate>
29088
- ${candidate}
29089
- </candidate>`;
29090
- }
29091
- function parseJudgeScore(response) {
29092
- const match = response.trim().match(/^([1-5])/);
29093
- if (!match) return null;
29094
- return parseInt(match[1], 10);
29095
- }
29096
- async function runValidation(input) {
29097
- const { llm, candidates, referenceObservations, sourceMessagesText, date: date5 } = input;
29098
- const userPrompt = distillationUser({
29099
- messages: sourceMessagesText,
29100
- date: date5
29101
- });
29102
- for (const candidate of candidates) {
29103
- if (candidate.id === input.sessionModelID) continue;
29104
- let candidateObservations = null;
29105
- try {
29106
- const raw = await llm.prompt(DISTILLATION_SYSTEM, userPrompt, {
29107
- model: { providerID: candidate.providerID, modelID: candidate.id },
29108
- workerID: "lore-distill",
29109
- thinking: false
29110
- });
29111
- if (raw) {
29112
- const match = raw.match(/<observations>([\s\S]*?)<\/observations>/);
29113
- candidateObservations = match ? match[1].trim() : raw.trim();
29114
- }
29115
- } catch (e) {
29116
- warn(`worker model validation: candidate ${candidate.id} failed:`, e);
29117
- continue;
29118
- }
29119
- const structural = structuralCheck(candidateObservations, referenceObservations);
29120
- if (!structural.passed) {
29121
- info(
29122
- `worker model validation: ${candidate.id} failed structural check: ${structural.reason}`
29123
- );
29124
- continue;
29125
- }
29126
- let judgeScore = null;
29127
- try {
29128
- const judgeResponse = await llm.prompt(
29129
- WORKER_JUDGE_SYSTEM,
29130
- workerJudgeUser(referenceObservations, candidateObservations),
29131
- { workerID: "lore-distill", thinking: false }
29132
- // use session model (no model override)
29133
- );
29134
- if (judgeResponse) {
29135
- judgeScore = parseJudgeScore(judgeResponse);
29136
- }
29137
- } catch (e) {
29138
- warn(`worker model validation: judge call failed for ${candidate.id}:`, e);
29139
- }
29140
- if (judgeScore !== null && judgeScore < 3) {
29141
- info(
29142
- `worker model validation: ${candidate.id} failed judge (score=${judgeScore})`
29143
- );
29144
- continue;
29145
- }
29146
- const fingerprint = computeModelFingerprint(
29147
- input.providerID,
29148
- input.sessionModelID,
29149
- candidates.map((c) => c.id)
29150
- );
29151
- const result = {
29152
- modelID: candidate.id,
29153
- providerID: candidate.providerID,
29154
- fingerprint,
29155
- validatedAt: Date.now(),
29156
- judgeScore
29157
- };
29158
- storeValidatedWorkerModel(result);
29159
- info(
29160
- `worker model validated: ${candidate.id} (judge=${judgeScore}) for provider ${input.providerID}`
29161
- );
29162
- return result;
29163
- }
29164
- clearValidatedWorkerModel(input.providerID);
29165
- info(
29166
- `worker model validation: no candidate passed for ${input.providerID} \u2014 cleared stale entry`
29167
- );
29168
- return null;
29169
- }
29170
- function resolveWorkerModel(providerID, configWorkerModel, configModel) {
29010
+ function resolveWorkerModel(_providerID, configWorkerModel, configModel) {
29171
29011
  if (configWorkerModel) return configWorkerModel;
29172
- const validated = getValidatedWorkerModel(providerID);
29173
- const MAX_AGE_MS = 24 * 60 * 60 * 1e3;
29174
- if (validated && Date.now() - validated.validatedAt <= MAX_AGE_MS) {
29175
- return { providerID: validated.providerID, modelID: validated.modelID };
29176
- }
29177
29012
  return configModel;
29178
29013
  }
29179
29014
  export {
@@ -29210,11 +29045,13 @@ export {
29210
29045
  formatKnowledge,
29211
29046
  ftsQuery,
29212
29047
  ftsQueryOr,
29048
+ getInstanceId,
29213
29049
  getLastTransformEstimate,
29214
29050
  getLastTransformedCount,
29215
29051
  getLastTurnAt,
29216
29052
  getLtmBudget,
29217
29053
  getLtmTokens,
29054
+ getMeta,
29218
29055
  h,
29219
29056
  importFromFile,
29220
29057
  importLoreFile,
@@ -29251,6 +29088,7 @@ export {
29251
29088
  setLastTurnAtForTest,
29252
29089
  setLtmTokens,
29253
29090
  setMaxLayer0Tokens,
29091
+ setMeta,
29254
29092
  setModelLimits,
29255
29093
  shouldImport,
29256
29094
  shouldImportLoreFile,