@fenglimg/fabric-shared 2.0.0-rc.1 → 2.0.0-rc.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.
@@ -1,52 +1,74 @@
1
1
  import {
2
+ FabExtractKnowledgeInputSchema,
3
+ FabExtractKnowledgeInputShape,
4
+ FabExtractKnowledgeOutputSchema,
5
+ FabReviewInputSchema,
6
+ FabReviewOutputSchema,
2
7
  KNOWLEDGE_TYPE_CODES,
3
8
  KnowledgeEntryFrontmatterSchema,
4
9
  KnowledgeTypeSchema,
5
10
  LayerSchema,
6
11
  MaturitySchema,
12
+ PROPOSED_REASON_DESCRIPTIONS,
13
+ ProposedReasonSchema,
7
14
  StableIdSchema,
8
15
  annotateIntentRequestSchema,
16
+ fabExtractKnowledgeAnnotations,
17
+ fabReviewAnnotations,
9
18
  formatKnowledgeId,
10
- getRulesAnnotations,
11
- getRulesInputSchema,
12
- getRulesOutputSchema,
19
+ getKnowledgeAnnotations,
20
+ getKnowledgeInputSchema,
21
+ getKnowledgeOutputSchema,
13
22
  historyStateQuerySchema,
14
23
  humanLockApproveRequestSchema,
15
24
  humanLockFileParamsSchema,
25
+ knowledgeSectionsAnnotations,
26
+ knowledgeSectionsInputSchema,
27
+ knowledgeSectionsOutputSchema,
16
28
  ledgerQuerySchema,
17
29
  ledgerSourceSchema,
18
30
  parseKnowledgeId,
19
31
  planContextAnnotations,
32
+ planContextHintNarrowEntrySchema,
33
+ planContextHintOutputSchema,
20
34
  planContextInputSchema,
21
35
  planContextOutputSchema,
22
- ruleSectionsAnnotations,
23
- ruleSectionsInputSchema,
24
- ruleSectionsOutputSchema,
25
36
  structuredWarningSchema
26
- } from "../chunk-HACPXMLL.js";
37
+ } from "../chunk-VQDCDCJA.js";
27
38
  export {
39
+ FabExtractKnowledgeInputSchema,
40
+ FabExtractKnowledgeInputShape,
41
+ FabExtractKnowledgeOutputSchema,
42
+ FabReviewInputSchema,
43
+ FabReviewOutputSchema,
28
44
  KNOWLEDGE_TYPE_CODES,
29
45
  KnowledgeEntryFrontmatterSchema,
30
46
  KnowledgeTypeSchema,
31
47
  LayerSchema,
32
48
  MaturitySchema,
49
+ PROPOSED_REASON_DESCRIPTIONS,
50
+ ProposedReasonSchema,
33
51
  StableIdSchema,
34
52
  annotateIntentRequestSchema,
53
+ fabExtractKnowledgeAnnotations,
54
+ fabReviewAnnotations,
35
55
  formatKnowledgeId,
36
- getRulesAnnotations,
37
- getRulesInputSchema,
38
- getRulesOutputSchema,
56
+ getKnowledgeAnnotations,
57
+ getKnowledgeInputSchema,
58
+ getKnowledgeOutputSchema,
39
59
  historyStateQuerySchema,
40
60
  humanLockApproveRequestSchema,
41
61
  humanLockFileParamsSchema,
62
+ knowledgeSectionsAnnotations,
63
+ knowledgeSectionsInputSchema,
64
+ knowledgeSectionsOutputSchema,
42
65
  ledgerQuerySchema,
43
66
  ledgerSourceSchema,
44
67
  parseKnowledgeId,
45
68
  planContextAnnotations,
69
+ planContextHintNarrowEntrySchema,
70
+ planContextHintOutputSchema,
46
71
  planContextInputSchema,
47
72
  planContextOutputSchema,
48
- ruleSectionsAnnotations,
49
- ruleSectionsInputSchema,
50
- ruleSectionsOutputSchema,
51
73
  structuredWarningSchema
52
74
  };
@@ -16,6 +16,8 @@ interface RuleDescription {
16
16
  layer_reason?: string;
17
17
  created_at?: string;
18
18
  tags?: string[];
19
+ relevance_scope?: "narrow" | "broad";
20
+ relevance_paths?: string[];
19
21
  }
20
22
  interface RuleDescriptionIndexItem {
21
23
  stable_id: string;
@@ -27,6 +29,8 @@ interface RuleDescriptionIndexItem {
27
29
  maturity?: "draft" | "verified" | "proven";
28
30
  layer?: "personal" | "team";
29
31
  layer_reason?: string;
32
+ relevance_scope?: "narrow" | "broad";
33
+ relevance_paths?: string[];
30
34
  }
31
35
  interface AgentsMetaNodeActivation {
32
36
  tier: AgentsActivationTier;
@@ -36,17 +40,17 @@ interface AgentsMetaNode {
36
40
  file: string;
37
41
  content_ref?: string;
38
42
  scope_glob: string;
39
- deps: string[];
40
- priority: "high" | "medium" | "low";
41
- level?: AgentsLayer;
42
- layer: AgentsLayer;
43
- topology_type: AgentsTopologyType;
44
43
  hash: string;
45
44
  stable_id?: string;
46
45
  identity_source?: AgentsIdentitySource;
47
46
  activation?: AgentsMetaNodeActivation;
48
47
  description?: RuleDescription;
49
48
  sections?: string[];
49
+ deps?: string[];
50
+ priority?: "high" | "medium" | "low";
51
+ level?: AgentsLayer;
52
+ layer?: AgentsLayer;
53
+ topology_type?: AgentsTopologyType;
50
54
  }
51
55
  interface AgentsMetaKnowledgeTypeCounters {
52
56
  MOD: number;
@@ -103,6 +107,8 @@ interface McpPayloadLimits {
103
107
  warnBytes?: number;
104
108
  hardBytes?: number;
105
109
  }
110
+ type KnowledgeLanguage = "match-existing" | "zh-CN" | "en";
111
+ type DefaultLayerFilter = "team" | "personal" | "both";
106
112
  interface FabricConfig {
107
113
  clientPaths?: ClientPaths;
108
114
  externalFixturePath?: string;
@@ -110,6 +116,8 @@ interface FabricConfig {
110
116
  auditMode?: AuditMode;
111
117
  audit_mode?: AuditMode;
112
118
  mcpPayloadLimits?: McpPayloadLimits;
119
+ knowledge_language?: KnowledgeLanguage;
120
+ default_layer_filter?: DefaultLayerFilter;
113
121
  }
114
122
 
115
- export type { AgentsActivationTier, AgentsIdentitySource, AgentsLayer, AgentsMeta, AgentsMetaCountersEnvelope, AgentsMetaKnowledgeTypeCounters, AgentsMetaNode, AgentsMetaNodeActivation, AgentsTopologyType, AiLedgerEntry, AuditMode, ClientPaths, FabricConfig, HumanLedgerEntry, HumanLockEntry, LedgerEntry, McpPayloadLimits, RuleDescription, RuleDescriptionIndexItem };
123
+ export type { AgentsActivationTier, AgentsIdentitySource, AgentsLayer, AgentsMeta, AgentsMetaCountersEnvelope, AgentsMetaKnowledgeTypeCounters, AgentsMetaNode, AgentsMetaNodeActivation, AgentsTopologyType, AiLedgerEntry, AuditMode, ClientPaths, DefaultLayerFilter, FabricConfig, HumanLedgerEntry, HumanLockEntry, KnowledgeLanguage, LedgerEntry, McpPayloadLimits, RuleDescription, RuleDescriptionIndexItem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fenglimg/fabric-shared",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,314 +0,0 @@
1
- // src/schemas/api-contracts.ts
2
- import { z } from "zod";
3
- var structuredWarningSchema = z.object({
4
- code: z.string(),
5
- file: z.string(),
6
- line: z.number().optional(),
7
- action_hint: z.string()
8
- });
9
- var _knowledgeTypeEnum = z.enum(["model", "decision", "guideline", "pitfall", "process"]);
10
- var _maturityEnum = z.enum(["draft", "verified", "proven"]);
11
- var _layerEnum = z.enum(["personal", "team"]);
12
- var _ruleDescriptionSchema = z.object({
13
- summary: z.string(),
14
- intent_clues: z.array(z.string()),
15
- tech_stack: z.array(z.string()),
16
- impact: z.array(z.string()),
17
- must_read_if: z.string(),
18
- entities: z.array(z.string()).optional(),
19
- // v2.0: optional knowledge-entry fields. Absent for v1.x rules; present for
20
- // entries that declare frontmatter `id/type/maturity/layer`.
21
- id: z.string().optional(),
22
- knowledge_type: _knowledgeTypeEnum.optional(),
23
- maturity: _maturityEnum.optional(),
24
- knowledge_layer: _layerEnum.optional(),
25
- layer_reason: z.string().optional(),
26
- created_at: z.string().optional()
27
- });
28
- var _descriptionIndexItemSchema = z.object({
29
- stable_id: z.string(),
30
- level: z.enum(["L0", "L1", "L2"]),
31
- required: z.boolean(),
32
- selectable: z.boolean(),
33
- description: _ruleDescriptionSchema,
34
- // v2.0: top-level knowledge surface for client-side filtering. Mirrors
35
- // description.* — exposed here so MCP clients can filter without reaching
36
- // into the nested payload.
37
- type: _knowledgeTypeEnum.optional(),
38
- maturity: _maturityEnum.optional(),
39
- layer: _layerEnum.optional(),
40
- layer_reason: z.string().optional()
41
- });
42
- var _requirementProfileSchema = z.object({
43
- target_path: z.string(),
44
- path_segments: z.array(z.string()),
45
- extension: z.string(),
46
- inferred_domain: z.array(z.string()),
47
- known_tech: z.array(z.string()),
48
- user_intent: z.string(),
49
- intent_tokens: z.array(z.string()),
50
- impact_hints: z.array(z.string()),
51
- detected_entities: z.array(z.string())
52
- });
53
- var _selectionPolicySchema = z.object({
54
- required_levels: z.tuple([z.literal("L0"), z.literal("L2")]),
55
- ai_selectable_levels: z.tuple([z.literal("L1")]),
56
- final_fetch_rule: z.literal("required_stable_ids + ai_selected_l1_stable_ids")
57
- });
58
- var planContextInputSchema = z.object({
59
- paths: z.array(z.string()).min(1).describe("Candidate file paths to build neutral rule selection context for"),
60
- intent: z.string().optional().describe("User-stated requirement or implementation intent; used only to build a neutral requirement profile"),
61
- known_tech: z.array(z.string()).optional().describe("Known technologies involved in the requirement profile"),
62
- detected_entities: z.record(z.array(z.string())).optional().describe("Optional path-keyed detected entities for the requirement profile"),
63
- client_hash: z.string().optional().describe("Revision hash from a prior fab_plan_context response; enables stale detection"),
64
- correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
65
- session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records"),
66
- include_deprecated: z.boolean().optional().describe(
67
- "When true, include description_index entries with maturity='deprecated'. Defaults to false (deprecated entries hidden). Note: 'deprecated' is reserved future state \u2014 today this filter is a no-op until MaturitySchema is widened."
68
- )
69
- });
70
- var planContextOutputSchema = z.object({
71
- revision_hash: z.string(),
72
- stale: z.boolean(),
73
- selection_token: z.string(),
74
- entries: z.array(
75
- z.object({
76
- path: z.string(),
77
- requirement_profile: _requirementProfileSchema,
78
- description_index: z.array(_descriptionIndexItemSchema),
79
- required_stable_ids: z.array(z.string()),
80
- ai_selectable_stable_ids: z.array(z.string()),
81
- initial_selected_stable_ids: z.array(z.string()),
82
- selection_policy: _selectionPolicySchema
83
- })
84
- ),
85
- shared: z.object({
86
- required_stable_ids: z.array(z.string()),
87
- ai_selectable_stable_ids: z.array(z.string()),
88
- description_index: z.array(_descriptionIndexItemSchema),
89
- preflight_diagnostics: z.array(
90
- z.object({
91
- code: z.literal("missing_description"),
92
- severity: z.literal("warn"),
93
- message: z.string(),
94
- stable_ids: z.array(z.string()).optional(),
95
- path: z.string().optional()
96
- })
97
- )
98
- }),
99
- warnings: z.array(structuredWarningSchema).optional()
100
- });
101
- var planContextAnnotations = {
102
- readOnlyHint: true,
103
- idempotentHint: true,
104
- destructiveHint: false,
105
- openWorldHint: false,
106
- title: "Plan rule context"
107
- };
108
- var _rulesEntrySchema = z.object({ path: z.string(), content: z.string() });
109
- var _humanLockedSchema = z.object({ file: z.string(), excerpt: z.string() });
110
- var _descriptionStubSchema = z.object({ path: z.string(), description: z.string() });
111
- var getRulesInputSchema = z.object({
112
- path: z.string().describe("Target file path to query rules for"),
113
- client_hash: z.string().optional().describe("Revision hash from prior fab_get_rules response; enables stale detection"),
114
- correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
115
- session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records")
116
- });
117
- var getRulesOutputSchema = z.object({
118
- revision_hash: z.string(),
119
- stale: z.boolean(),
120
- rules: z.object({
121
- L0: z.string(),
122
- L1: z.array(_rulesEntrySchema),
123
- L2: z.array(_rulesEntrySchema),
124
- human_locked_nearby: z.array(_humanLockedSchema),
125
- description_stubs: z.array(_descriptionStubSchema).optional()
126
- }),
127
- warnings: z.array(structuredWarningSchema).optional()
128
- });
129
- var getRulesAnnotations = {
130
- readOnlyHint: true,
131
- idempotentHint: true,
132
- destructiveHint: false,
133
- openWorldHint: false,
134
- title: "Get rule content"
135
- };
136
- var RULE_SECTION_NAMES_TUPLE = ["MISSION_STATEMENT", "MANDATORY_INJECTION", "BUSINESS_LOGIC_CHUNKS", "CONTEXT_INFO"];
137
- var ruleSectionsInputSchema = z.object({
138
- selection_token: z.string().min(1).describe("Selection token returned by fab_plan_context"),
139
- sections: z.array(z.enum(RULE_SECTION_NAMES_TUPLE)).min(1).describe("Structured rule sections to fetch"),
140
- ai_selected_stable_ids: z.array(z.string()).describe("AI-selected L1 stable_ids chosen from fab_plan_context ai_selectable_stable_ids"),
141
- ai_selection_reasons: z.record(z.string().min(1)).describe("Reason for each AI-selected L1 stable_id"),
142
- correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
143
- session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records")
144
- });
145
- var ruleSectionsOutputSchema = z.object({
146
- revision_hash: z.string(),
147
- precedence: z.tuple([z.literal("L2"), z.literal("L1"), z.literal("L0")]),
148
- selected_stable_ids: z.array(z.string()),
149
- rules: z.array(
150
- z.object({
151
- stable_id: z.string(),
152
- level: z.enum(["L0", "L1", "L2"]),
153
- path: z.string(),
154
- sections: z.record(z.string())
155
- })
156
- ),
157
- diagnostics: z.array(
158
- z.discriminatedUnion("code", [
159
- z.object({
160
- code: z.literal("missing_section"),
161
- severity: z.literal("warn"),
162
- stable_id: z.string(),
163
- section: z.enum(RULE_SECTION_NAMES_TUPLE),
164
- message: z.string()
165
- }),
166
- // v2.0: warn-level diagnostic for un-migrated v1.x entries (no
167
- // knowledge_type and no knowledge_layer). Does NOT block selection.
168
- z.object({
169
- code: z.literal("missing_knowledge_metadata"),
170
- severity: z.literal("warn"),
171
- stable_id: z.string(),
172
- message: z.string()
173
- })
174
- ])
175
- ),
176
- warnings: z.array(structuredWarningSchema).optional()
177
- });
178
- var ruleSectionsAnnotations = {
179
- readOnlyHint: true,
180
- idempotentHint: true,
181
- destructiveHint: false,
182
- openWorldHint: false,
183
- title: "Filter rule sections"
184
- };
185
- var ledgerSourceSchema = z.enum(["ai", "human"]);
186
- var timestampFilterSchema = z.preprocess((value) => {
187
- if (value === void 0 || value === null || value === "") {
188
- return void 0;
189
- }
190
- if (typeof value === "number") {
191
- return value;
192
- }
193
- if (typeof value === "string") {
194
- const trimmed = value.trim();
195
- if (trimmed.length === 0) {
196
- return void 0;
197
- }
198
- if (/^\d+$/.test(trimmed)) {
199
- return Number.parseInt(trimmed, 10);
200
- }
201
- const parsed = Date.parse(trimmed);
202
- return Number.isNaN(parsed) ? value : parsed;
203
- }
204
- return value;
205
- }, z.number().int().nonnegative());
206
- var ledgerQuerySchema = z.object({
207
- source: ledgerSourceSchema.optional(),
208
- since: timestampFilterSchema.optional()
209
- });
210
- var historyStateQuerySchema = z.object({
211
- ledger_id: z.string().trim().min(1).optional(),
212
- ts: timestampFilterSchema.optional()
213
- }).superRefine((value, ctx) => {
214
- const provided = [value.ledger_id, value.ts].filter((entry) => entry !== void 0);
215
- if (provided.length !== 1) {
216
- ctx.addIssue({
217
- code: z.ZodIssueCode.custom,
218
- message: "Provide exactly one of ledger_id or ts.",
219
- path: ["ledger_id"]
220
- });
221
- }
222
- });
223
- var humanLockApproveRequestSchema = z.object({
224
- file: z.string().min(1),
225
- start_line: z.number().int().positive(),
226
- end_line: z.number().int().positive(),
227
- new_hash: z.string().min(1)
228
- });
229
- var humanLockFileParamsSchema = z.object({
230
- file: z.string().min(1)
231
- });
232
- var annotateIntentRequestSchema = z.object({
233
- ledger_entry_id: z.string().min(1),
234
- annotation: z.string().trim().min(1)
235
- });
236
- var KnowledgeTypeSchema = z.enum([
237
- "model",
238
- // entities, data structures, relationships
239
- "decision",
240
- // architectural/technical choices with rationale
241
- "guideline",
242
- // recommended practices (recommend) or anti-patterns (avoid)
243
- "pitfall",
244
- // known risks, failure modes, troubleshooting
245
- "process"
246
- // workflows, state machines, operational steps
247
- ]);
248
- var MaturitySchema = z.enum(["draft", "verified", "proven"]);
249
- var LayerSchema = z.enum(["personal", "team"]);
250
- var StableIdSchema = z.string().regex(/^K[PT]-(MOD|DEC|GLD|PIT|PRO)-\d{4,}$/);
251
- var KnowledgeEntryFrontmatterSchema = z.object({
252
- id: StableIdSchema,
253
- // e.g., "KT-DEC-0042"
254
- type: KnowledgeTypeSchema,
255
- // one of 5 types
256
- maturity: MaturitySchema,
257
- // draft | verified | proven
258
- layer: LayerSchema,
259
- // personal | team
260
- layer_reason: z.string().optional(),
261
- // why this layer (for ambiguous cases)
262
- created_at: z.string()
263
- // ISO 8601 timestamp
264
- // Note: 'tags' and other fields can be added later but core schema is these 6
265
- });
266
- var KNOWLEDGE_TYPE_CODES = {
267
- model: "MOD",
268
- decision: "DEC",
269
- guideline: "GLD",
270
- pitfall: "PIT",
271
- process: "PRO"
272
- };
273
- function formatKnowledgeId(layer, type, counter) {
274
- const layerPrefix = layer === "personal" ? "KP" : "KT";
275
- const typeCode = KNOWLEDGE_TYPE_CODES[type];
276
- return `${layerPrefix}-${typeCode}-${String(counter).padStart(4, "0")}`;
277
- }
278
- function parseKnowledgeId(id) {
279
- const match = id.match(/^(KP|KT)-(MOD|DEC|GLD|PIT|PRO)-(\d+)$/);
280
- if (!match) return null;
281
- const layer = match[1] === "KP" ? "personal" : "team";
282
- const typeCode = match[2];
283
- const entry = Object.entries(KNOWLEDGE_TYPE_CODES).find(([, code]) => code === typeCode);
284
- if (!entry) return null;
285
- const type = entry[0];
286
- return { layer, type, counter: parseInt(match[3], 10) };
287
- }
288
-
289
- export {
290
- structuredWarningSchema,
291
- planContextInputSchema,
292
- planContextOutputSchema,
293
- planContextAnnotations,
294
- getRulesInputSchema,
295
- getRulesOutputSchema,
296
- getRulesAnnotations,
297
- ruleSectionsInputSchema,
298
- ruleSectionsOutputSchema,
299
- ruleSectionsAnnotations,
300
- ledgerSourceSchema,
301
- ledgerQuerySchema,
302
- historyStateQuerySchema,
303
- humanLockApproveRequestSchema,
304
- humanLockFileParamsSchema,
305
- annotateIntentRequestSchema,
306
- KnowledgeTypeSchema,
307
- MaturitySchema,
308
- LayerSchema,
309
- StableIdSchema,
310
- KnowledgeEntryFrontmatterSchema,
311
- KNOWLEDGE_TYPE_CODES,
312
- formatKnowledgeId,
313
- parseKnowledgeId
314
- };