@fenglimg/fabric-server 2.0.0-rc.22 → 2.0.0-rc.25

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.
@@ -14,7 +14,7 @@ import {
14
14
  readEventLedger,
15
15
  runDoctorReport,
16
16
  sha256
17
- } from "./chunk-7N3FW5LX.js";
17
+ } from "./chunk-HAXROPQM.js";
18
18
 
19
19
  // src/http.ts
20
20
  import { randomUUID as randomUUID2 } from "crypto";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Server } from 'node:http';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import { AgentsMeta, KnowledgeTestIndex, AgentsLayer, AgentsTopologyType, Layer, KnowledgeType, StableId, AgentsMetaCounters, EventLedgerEventInput, EventLedgerEvent, RuleDescriptionIndexItem } from '@fenglimg/fabric-shared';
3
+ import { AgentsMeta, KnowledgeTestIndex, AgentsLayer, AgentsTopologyType, KnowledgeType, Layer, StableId, AgentsMetaCounters, EventLedgerEventInput, EventLedgerEvent, RuleDescriptionIndexItem } from '@fenglimg/fabric-shared';
4
4
  import { FabExtractKnowledgeInput, FabExtractKnowledgeOutput, FabReviewInput, FabReviewOutput } from '@fenglimg/fabric-shared/schemas/api-contracts';
5
5
  import { IOFabricError } from '@fenglimg/fabric-shared/errors';
6
6
 
@@ -97,12 +97,26 @@ type DoctorApplyLintReport = {
97
97
  declare function runDoctorReport(target: string): Promise<DoctorReport>;
98
98
  declare function runDoctorFix(target: string): Promise<DoctorFixReport>;
99
99
  declare function runDoctorApplyLint(target: string): Promise<DoctorApplyLintReport>;
100
+ type CiteContractMetrics = {
101
+ decisions_cited: number;
102
+ pitfalls_cited: number;
103
+ contract_with: number;
104
+ contract_missing: number;
105
+ hard_violated: number;
106
+ cite_id_unresolved: number;
107
+ skip_count: Record<string, number>;
108
+ };
109
+ type CiteLayerTypeBreakdown = {
110
+ team: Record<string, number>;
111
+ personal: Record<string, number>;
112
+ };
100
113
  type CiteCoverageReport = {
101
114
  status: "ok" | "skipped";
102
115
  marker_ts: number;
103
116
  marker_emitted_now: boolean;
104
117
  since_ts: number;
105
118
  client_filter: "cc" | "codex" | "cursor" | "all";
119
+ layer_filter?: "team" | "personal" | "all";
106
120
  metrics: {
107
121
  edits_touched: number;
108
122
  qualifying_cites: number;
@@ -112,12 +126,55 @@ type CiteCoverageReport = {
112
126
  };
113
127
  per_client?: Record<string, Partial<CiteCoverageReport["metrics"]>>;
114
128
  dismissed_reason_histogram?: Record<string, number>;
129
+ none_reason_histogram?: Record<string, number>;
130
+ contract_metrics_status?: "ok" | "skipped:bootstrap_drift" | "awaiting_marker";
131
+ contract_metrics?: CiteContractMetrics;
132
+ per_layer_type?: CiteLayerTypeBreakdown;
133
+ contract_marker_ts?: number;
115
134
  generated_at: string;
116
135
  };
117
136
  declare function runDoctorCiteCoverage(projectRoot: string, options: {
118
137
  since: number;
119
138
  client: "cc" | "codex" | "cursor" | "all";
139
+ layer?: "team" | "personal" | "all";
120
140
  }): Promise<CiteCoverageReport>;
141
+ type ArchiveHistoryEntry = {
142
+ session_id_short: string;
143
+ last_attempted_at: string;
144
+ outcome: "proposed" | "viability_failed" | "user_dismissed" | "skipped_no_signal";
145
+ candidates_proposed: number;
146
+ covered_through_ts: number;
147
+ age_since_covered_hours: number;
148
+ };
149
+ type ArchiveHistoryReport = {
150
+ entries: ArchiveHistoryEntry[];
151
+ total: number;
152
+ since_ms: number;
153
+ generated_at: string;
154
+ };
155
+ declare function runDoctorArchiveHistory(projectRoot: string, options: {
156
+ since: number;
157
+ }): Promise<ArchiveHistoryReport>;
158
+ type EnrichDescriptionsMode = "auto" | "interactive";
159
+ type EnrichDescriptionsCandidate = {
160
+ path: string;
161
+ missing: Array<"intent_clues" | "tech_stack" | "impact" | "must_read_if">;
162
+ modified: boolean;
163
+ added_fields: Array<"intent_clues" | "tech_stack" | "impact" | "must_read_if">;
164
+ error?: string;
165
+ };
166
+ type EnrichDescriptionsReport = {
167
+ mode: EnrichDescriptionsMode;
168
+ dryRun: boolean;
169
+ scanned: number;
170
+ modified: number;
171
+ skipped: number;
172
+ candidates: EnrichDescriptionsCandidate[];
173
+ };
174
+ declare function enrichDescriptions(projectRoot: string, opts?: {
175
+ auto?: boolean;
176
+ dryRun?: boolean;
177
+ }): Promise<EnrichDescriptionsReport>;
121
178
 
122
179
  type KnowledgeMetaBuildSource = "doctor_fix" | "sync_meta";
123
180
  type KnowledgeMetaBuildResult = {
@@ -128,6 +185,31 @@ type KnowledgeMetaBuildResult = {
128
185
  type WriteKnowledgeMetaOptions = {
129
186
  source: KnowledgeMetaBuildSource;
130
187
  };
188
+ /**
189
+ * v2.0-rc.24 TASK-07: Load a Map<stable_id, knowledge_type> from the
190
+ * project's `.fabric/agents.meta.json`. Consumed by the doctor cite-coverage
191
+ * routing (TASK-08) to dispatch cites to the correct policy bucket
192
+ * (decision/pitfall = strict contract / model = reference-only /
193
+ * guideline+process = deferred to rc.25 LLM-judge). Cited ids absent from
194
+ * this map fall into the `cite_id_unresolved` bucket.
195
+ *
196
+ * **Singular knowledge_type contract (rc.24 lock):** the returned map values
197
+ * are the SINGULAR `KnowledgeType` enum (`"model" | "decision" | "guideline"
198
+ * | "pitfall" | "process"`) — matching both the on-disk `agents.meta.json`
199
+ * storage AND the canonical `KnowledgeTypeSchema` exported from
200
+ * `@fenglimg/fabric-shared`. No normalization happens at this boundary; the
201
+ * loader is a thin extract over engine-maintained meta. Downstream callers
202
+ * (TASK-08 doctor) must match against the singular enum.
203
+ *
204
+ * Both team (KT-*) and personal (KP-*) entries are included — they live in
205
+ * the same `meta.nodes` map.
206
+ *
207
+ * Graceful on failure: a missing meta file, malformed JSON, or schema
208
+ * validation failure all yield an empty Map (no throw). The doctor will then
209
+ * surface every cite as `cite_id_unresolved`, which is the safe degraded
210
+ * mode.
211
+ */
212
+ declare function loadKbIdTypeMap(projectRootInput: string): Promise<Map<string, KnowledgeType>>;
131
213
  declare function buildKnowledgeMeta(projectRootInput: string): Promise<KnowledgeMetaBuildResult>;
132
214
  declare function writeKnowledgeMeta(projectRootInput: string, options: WriteKnowledgeMetaOptions): Promise<KnowledgeMetaBuildResult>;
133
215
  declare function computeKnowledgeBasedAgentsMeta(projectRootInput: string, existingMeta?: AgentsMeta): Promise<AgentsMeta>;
@@ -176,8 +258,11 @@ declare class KnowledgeIdAllocator {
176
258
  /**
177
259
  * Append-evidence-on-collision service for fab_extract_knowledge.
178
260
  *
179
- * Idempotency_key = sha256({source_session, type, slug}). When the same
180
- * triple hits an existing pending file (verified by frontmatter
261
+ * Idempotency_key = sha256({source_session: source_sessions[0], type, slug}).
262
+ * The `source_session` key inside the hash payload is FROZEN for backward
263
+ * compatibility with on-disk pending entries written before rc.23 — changing
264
+ * it would invalidate every existing `x-fabric-idempotency-key`. When the
265
+ * same triple hits an existing pending file (verified by frontmatter
181
266
  * `x-fabric-idempotency-key`), the body is preserved and a fresh
182
267
  * `## Evidence (call N)` section is appended — LLM-regenerated summaries
183
268
  * stay observable without overwriting prior context.
@@ -333,8 +418,14 @@ interface KnowledgeSyncReport {
333
418
  */
334
419
  declare function ensureKnowledgeFresh(projectRoot: string, opts?: KnowledgeSyncOptions): Promise<KnowledgeSyncReport>;
335
420
  interface ReconcileKnowledgeOptions {
336
- /** Identifies who triggered the reconcile; controls which summary ledger event is written. */
337
- trigger?: "startup" | "doctor" | "manual";
421
+ /**
422
+ * Identifies who triggered the reconcile; controls which summary ledger event is written.
423
+ *
424
+ * v2.0.0-rc.23 TASK-005 (a-B): `auto-heal-description` added so plan_context
425
+ * can drive a full reconcile when it detects nodes with `description === undefined`
426
+ * (legacy meta drift the revision-hash gate cannot detect).
427
+ */
428
+ trigger?: "startup" | "doctor" | "manual" | "auto-heal-description";
338
429
  }
339
430
  /**
340
431
  * Full scan + rewrites agents.meta.json with ground-truth disk state + emits
@@ -405,4 +496,4 @@ declare function startHttpServer(options: {
405
496
  authToken?: string;
406
497
  }): Promise<Server>;
407
498
 
408
- export { AGENTS_MD_RESOURCE_URI, type AcquireOptions, type CiteCoverageReport, type DoctorApplyLintMutation, type DoctorApplyLintMutationKind, type DoctorApplyLintReport, type DoctorFixReport, type DoctorIssue, type DoctorReport, EVENT_LEDGER_PATH, type InFlightTracker, KnowledgeIdAllocator, type KnowledgeMetaBuildResult, type KnowledgeMetaBuildSource, type KnowledgeSyncLedgerEvent, type KnowledgeSyncOptions, type KnowledgeSyncReport, LEDGER_PATH, LEGACY_LEDGER_PATH, type LedgerEvent, type LockState, type PlanContextInput, type PlanContextResult, type ReconcileKnowledgeOptions, type RequirementProfile, type SelectionTokenState, ServeLockHeldError, type ShutdownHandlerDeps, type StructuredWarning, type WriteKnowledgeMetaOptions, acquireLock, appendEventLedgerEvent, buildKnowledgeMeta, checkLockOrThrow, computeKnowledgeBasedAgentsMeta, computeKnowledgeTestIndex, createFabricServer, createInFlightTracker, createShutdownHandler, deriveKnowledgeMetaLayer, deriveKnowledgeMetaTopologyType, ensureKnowledgeFresh, extractKnowledge, flushAndSyncEventLedger, formatPreexistingRootMessage, getEventLedgerPath, getLedgerPath, getLegacyLedgerPath, isSameKnowledgeTestIndex, planContext, readLockState, readSelectionToken, reconcileKnowledge, releaseLock, reviewKnowledge, runDoctorApplyLint, runDoctorCiteCoverage, runDoctorFix, runDoctorReport, stableStringify, startHttpServer, startStdioServer, writeKnowledgeMeta };
499
+ export { AGENTS_MD_RESOURCE_URI, type AcquireOptions, type ArchiveHistoryEntry, type ArchiveHistoryReport, type CiteCoverageReport, type DoctorApplyLintMutation, type DoctorApplyLintMutationKind, type DoctorApplyLintReport, type DoctorFixReport, type DoctorIssue, type DoctorReport, EVENT_LEDGER_PATH, type EnrichDescriptionsCandidate, type EnrichDescriptionsMode, type EnrichDescriptionsReport, type InFlightTracker, KnowledgeIdAllocator, type KnowledgeMetaBuildResult, type KnowledgeMetaBuildSource, type KnowledgeSyncLedgerEvent, type KnowledgeSyncOptions, type KnowledgeSyncReport, LEDGER_PATH, LEGACY_LEDGER_PATH, type LedgerEvent, type LockState, type PlanContextInput, type PlanContextResult, type ReconcileKnowledgeOptions, type RequirementProfile, type SelectionTokenState, ServeLockHeldError, type ShutdownHandlerDeps, type StructuredWarning, type WriteKnowledgeMetaOptions, acquireLock, appendEventLedgerEvent, buildKnowledgeMeta, checkLockOrThrow, computeKnowledgeBasedAgentsMeta, computeKnowledgeTestIndex, createFabricServer, createInFlightTracker, createShutdownHandler, deriveKnowledgeMetaLayer, deriveKnowledgeMetaTopologyType, enrichDescriptions, ensureKnowledgeFresh, extractKnowledge, flushAndSyncEventLedger, formatPreexistingRootMessage, getEventLedgerPath, getLedgerPath, getLegacyLedgerPath, isSameKnowledgeTestIndex, loadKbIdTypeMap, planContext, readLockState, readSelectionToken, reconcileKnowledge, releaseLock, reviewKnowledge, runDoctorApplyLint, runDoctorArchiveHistory, runDoctorCiteCoverage, runDoctorFix, runDoctorReport, stableStringify, startHttpServer, startStdioServer, writeKnowledgeMeta };