@fenglimg/fabric-server 2.3.0-rc.1 → 2.3.0-rc.3

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { FabExtractKnowledgeInput, FabExtractKnowledgeOutput, FabReviewInput, FabReviewOutput, FabPendingInput, FabPendingOutput } from '@fenglimg/fabric-shared/schemas/api-contracts';
3
- import { EventLedgerEventInput, EventLedgerEvent, RuleDescriptionIndexItem, LedgerEntry, AgentsMeta } from '@fenglimg/fabric-shared';
3
+ import { EventLedgerEventInput, EventLedgerEvent, RuleDescriptionIndexItem, RecallScore, RecallScoreBreakdown, LedgerEntry, AgentsMeta } from '@fenglimg/fabric-shared';
4
4
  import { PayloadGuardOptions } from '@fenglimg/fabric-shared/node/mcp-payload-guard';
5
5
 
6
6
  interface InFlightTracker {
@@ -394,6 +394,29 @@ interface Bm25Model {
394
394
  * query property).
395
395
  */
396
396
  scoreDoc(id: string, queryTerms: string[]): number;
397
+ /**
398
+ * P1 recall-engine-refactor (TASK-002): the plain JSON-safe snapshot of the
399
+ * corpus statistics this model scores against, attached so the model can be
400
+ * serialized to disk (`serializeBm25Model`) and a cold hook can `rehydrate`
401
+ * an identical scorer without re-tokenizing the corpus.
402
+ */
403
+ readonly __serialized: SerializedBm25Model;
404
+ }
405
+ interface SerializedBm25Model {
406
+ /** Schema/format version — bump on any layout change so a stale on-disk cache
407
+ * (different shape) is detected and discarded rather than mis-rehydrated. */
408
+ version: 1;
409
+ totalDocs: number;
410
+ /** term → document frequency (union-of-fields df), as [term, count] pairs. */
411
+ documentFrequency: [string, number][];
412
+ /** Per-field corpus average length. */
413
+ avgFieldLength: Record<Bm25Field, number>;
414
+ /** Per-doc stats: id → { per-field [term,freq] pairs, per-field length }. */
415
+ perDoc: {
416
+ id: string;
417
+ fieldTermFreq: Record<Bm25Field, [string, number][]>;
418
+ fieldLength: Record<Bm25Field, number>;
419
+ }[];
397
420
  }
398
421
  /**
399
422
  * Build a BM25F model over `docs`. Corpus statistics (per-field document
@@ -507,6 +530,31 @@ declare function runDoctorConflictLint(projectRoot: string, opts?: {
507
530
  judge?: ConflictJudge;
508
531
  }): Promise<ConflictLintReport>;
509
532
 
533
+ declare function readEmbedConfig(projectRoot: string): {
534
+ enabled: boolean;
535
+ weight: number;
536
+ model: string;
537
+ };
538
+ declare function readFusion(projectRoot: string): "additive" | "rrf" | "auto";
539
+
540
+ interface Embedder {
541
+ embed(texts: string[]): Promise<number[][]>;
542
+ }
543
+ declare const OPTIONAL_EMBED_PACKAGE = "fastembed";
544
+ declare function defaultEmbedCacheDir(): string;
545
+ /**
546
+ * Lazy-load the optional fastembed embedder, pinned to CPU + cache-only. Returns
547
+ * null (cached) when the package is not installed or initialization throws, so
548
+ * every caller degrades to the text-only path. Never throws.
549
+ *
550
+ * v2.1 ③: `modelName` (a fastembed EmbeddingModel enum value) selects the
551
+ * embedding model — the caller threads `embed_model` config through so the
552
+ * Chinese-heavy KB no longer embeds against fastembed's English default. The
553
+ * load is cached per-process; the FIRST model wins (a config change needs a
554
+ * server restart, already the norm for MCP config changes).
555
+ */
556
+ declare function loadEmbedder(modelName?: string): Promise<Embedder | null>;
557
+
510
558
  interface RetiredToken {
511
559
  /** The exact dead token as it appears in agent-facing text. */
512
560
  token: string;
@@ -594,8 +642,10 @@ declare function reviewKnowledge(projectRoot: string, input: FabReviewInput): Pr
594
642
  * from `reviewKnowledge`. list browses the store-backed pending backlog;
595
643
  * search ranges over BOTH pending and canonical knowledge. Neither mutates
596
644
  * state — the fab_pending tool is registered readOnlyHint:true / idempotentHint:true.
597
- * The underlying listPending / searchEntries helpers are unchanged (verbatim
598
- * relocation), so behavior is identical to the prior fab_review list/search.
645
+ * P1 recall-engine-refactor (TASK-005): search now routes through `triageSearch`,
646
+ * which gates on the substring query then RANKS the matches via the shared
647
+ * rankDescriptionItems('triage') — NO top_k, NO floor, so pending review never
648
+ * silently drops a match. The old substring-only search machine is gone.
599
649
  */
600
650
  declare function reviewPending(projectRoot: string, input: FabPendingInput): Promise<FabPendingOutput>;
601
651
 
@@ -729,6 +779,7 @@ type PlanContextResult = {
729
779
  previous_revision_hash?: string;
730
780
  redirects?: Record<string, string>;
731
781
  related_appended?: Record<string, string>;
782
+ candidate_scores?: Map<string, RecallScore>;
732
783
  /** Internal service→tool signal; stripped before MCP output. */
733
784
  payload_trimmed?: boolean;
734
785
  /** Internal service→tool signal; stripped before MCP output. */
@@ -773,8 +824,10 @@ type RecallEntry = {
773
824
  alias: string;
774
825
  };
775
826
  body_in_context?: boolean;
827
+ score?: number;
828
+ score_breakdown?: RecallScoreBreakdown;
776
829
  };
777
- type RecallResult = Omit<PlanContextResult, "selection_token" | "payload_trimmed" | "payload_over_budget" | "entries" | "candidates"> & {
830
+ type RecallResult = Omit<PlanContextResult, "selection_token" | "payload_trimmed" | "payload_over_budget" | "entries" | "candidates" | "candidate_scores"> & {
778
831
  entries: RecallEntry[];
779
832
  directive: string;
780
833
  next_steps?: string[];
@@ -921,4 +974,4 @@ interface ShutdownHandlerDeps {
921
974
  */
922
975
  declare function createShutdownHandler(deps: ShutdownHandlerDeps): () => void;
923
976
 
924
- export { AGENTS_MD_RESOURCE_URI, type AlwaysActiveBody, type ArchiveHistoryEntry, type ArchiveHistoryReport, COLD_EVAL_RUBRIC, type CiteCoverageReport, type ColdEvalBatch, type ColdEvalCandidate, type ColdEvalVerdict, type ConflictEntry, type ConflictJudge, type ConflictLintReport, type ConflictPair, type ConflictVerdict, DEFAULT_CONFLICT_SIMILARITY_THRESHOLD, type DoctorApplyLintMutation, type DoctorApplyLintMutationKind, type DoctorApplyLintReport, type DoctorFixReport, type DoctorIssue, type DoctorReport, EVENT_LEDGER_PATH, type EnrichDescriptionsCandidate, type EnrichDescriptionsMode, type EnrichDescriptionsReport, FABRIC_SERVER_INSTRUCTIONS, type HistoryAllReport, type HistoryDayRow, type InFlightTracker, type KnowledgeCensus, LEDGER_PATH, LEGACY_LEDGER_PATH, METRICS_LEDGER_PATH, METRIC_COUNTER_NAMES, type MetricCounterName, type MetricsRow, type PlanContextInput, type PlanContextResult, RETIRED_TOKENS, type RecallInput, type RecallResult, type RequirementProfile, type RetiredReferenceHit, type RetiredReferenceInspection, type RetiredToken, type SelectionTokenState, type ShutdownHandlerDeps, type SurfaceVerdict, type UnboundProjectViolation, type WhyNotSurfacedResult, appendEventLedgerEvent, buildAlwaysActiveBodies, buildColdEvalBatch, buildKnowledgeCensus, bumpCounter, contextCache, createFabricServer, createInFlightTracker, createShutdownHandler, detectUnboundProject, drainCounters, enrichDescriptions, explainWhyNotSurfaced, extractKnowledge, findConflictCandidates, flushAndSyncEventLedger, flushMetrics, formatPreexistingRootMessage, getEventLedgerPath, getLedgerPath, getLegacyLedgerPath, getMetricsLedgerPath, inspectRetiredReferences, lintConflicts, loadConflictEntries, pairSimilarity, planContext, readEventLedger, readLedger, readMetrics, readSelectionToken, recall, rehydrateAgentsMetaAt, resolveLedgerPaths, reviewKnowledge, reviewPending, runDoctorApplyLint, runDoctorArchiveHistory, runDoctorCiteCoverage, runDoctorConflictLint, runDoctorFix, runDoctorHistoryAll, runDoctorReport, startMetricsFlush, startRotationTick, startStdioServer, stopMetricsFlush, stopRotationTick };
977
+ export { AGENTS_MD_RESOURCE_URI, type AlwaysActiveBody, type ArchiveHistoryEntry, type ArchiveHistoryReport, COLD_EVAL_RUBRIC, type CiteCoverageReport, type ColdEvalBatch, type ColdEvalCandidate, type ColdEvalVerdict, type ConflictEntry, type ConflictJudge, type ConflictLintReport, type ConflictPair, type ConflictVerdict, DEFAULT_CONFLICT_SIMILARITY_THRESHOLD, type DoctorApplyLintMutation, type DoctorApplyLintMutationKind, type DoctorApplyLintReport, type DoctorFixReport, type DoctorIssue, type DoctorReport, EVENT_LEDGER_PATH, type EnrichDescriptionsCandidate, type EnrichDescriptionsMode, type EnrichDescriptionsReport, FABRIC_SERVER_INSTRUCTIONS, type HistoryAllReport, type HistoryDayRow, type InFlightTracker, type KnowledgeCensus, LEDGER_PATH, LEGACY_LEDGER_PATH, METRICS_LEDGER_PATH, METRIC_COUNTER_NAMES, type MetricCounterName, type MetricsRow, OPTIONAL_EMBED_PACKAGE, type PlanContextInput, type PlanContextResult, RETIRED_TOKENS, type RecallInput, type RecallResult, type RequirementProfile, type RetiredReferenceHit, type RetiredReferenceInspection, type RetiredToken, type SelectionTokenState, type ShutdownHandlerDeps, type SurfaceVerdict, type UnboundProjectViolation, type WhyNotSurfacedResult, appendEventLedgerEvent, buildAlwaysActiveBodies, buildColdEvalBatch, buildKnowledgeCensus, bumpCounter, contextCache, createFabricServer, createInFlightTracker, createShutdownHandler, defaultEmbedCacheDir, detectUnboundProject, drainCounters, enrichDescriptions, explainWhyNotSurfaced, extractKnowledge, findConflictCandidates, flushAndSyncEventLedger, flushMetrics, formatPreexistingRootMessage, getEventLedgerPath, getLedgerPath, getLegacyLedgerPath, getMetricsLedgerPath, inspectRetiredReferences, lintConflicts, loadConflictEntries, loadEmbedder, pairSimilarity, planContext, readEmbedConfig, readEventLedger, readFusion, readLedger, readMetrics, readSelectionToken, recall, rehydrateAgentsMetaAt, resolveLedgerPaths, reviewKnowledge, reviewPending, runDoctorApplyLint, runDoctorArchiveHistory, runDoctorCiteCoverage, runDoctorConflictLint, runDoctorFix, runDoctorHistoryAll, runDoctorReport, startMetricsFlush, startRotationTick, startStdioServer, stopMetricsFlush, stopRotationTick };