@fenglimg/fabric-shared 1.6.0 → 1.8.0-rc.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.
- package/dist/chunk-3SZRB42B.js +90 -0
- package/dist/{chunk-KNZIX6IL.js → chunk-7A3RSITZ.js} +119 -113
- package/dist/chunk-GI6L6VTT.js +176 -0
- package/dist/chunk-KV27CZH3.js +223 -0
- package/dist/errors/index.d.ts +65 -0
- package/dist/errors/index.js +30 -0
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/index.d.ts +1523 -177
- package/dist/index.js +255 -60
- package/dist/node/atomic-write.d.ts +14 -0
- package/dist/node/atomic-write.js +60 -0
- package/dist/node/bootstrap-guide.d.ts +12 -0
- package/dist/node/bootstrap-guide.js +52 -0
- package/dist/node/mcp-payload-guard.d.ts +16 -0
- package/dist/node/mcp-payload-guard.js +40 -0
- package/dist/node.js +3 -172
- package/dist/schemas/api-contracts.d.ts +883 -0
- package/dist/schemas/api-contracts.js +36 -0
- package/dist/types/index.d.ts +7 -4
- package/package.json +28 -4
|
@@ -0,0 +1,223 @@
|
|
|
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 _ruleDescriptionSchema = z.object({
|
|
10
|
+
summary: z.string(),
|
|
11
|
+
intent_clues: z.array(z.string()),
|
|
12
|
+
tech_stack: z.array(z.string()),
|
|
13
|
+
impact: z.array(z.string()),
|
|
14
|
+
must_read_if: z.string(),
|
|
15
|
+
entities: z.array(z.string()).optional()
|
|
16
|
+
});
|
|
17
|
+
var _descriptionIndexItemSchema = z.object({
|
|
18
|
+
stable_id: z.string(),
|
|
19
|
+
level: z.enum(["L0", "L1", "L2"]),
|
|
20
|
+
required: z.boolean(),
|
|
21
|
+
selectable: z.boolean(),
|
|
22
|
+
description: _ruleDescriptionSchema
|
|
23
|
+
});
|
|
24
|
+
var _requirementProfileSchema = z.object({
|
|
25
|
+
target_path: z.string(),
|
|
26
|
+
path_segments: z.array(z.string()),
|
|
27
|
+
extension: z.string(),
|
|
28
|
+
inferred_domain: z.array(z.string()),
|
|
29
|
+
known_tech: z.array(z.string()),
|
|
30
|
+
user_intent: z.string(),
|
|
31
|
+
intent_tokens: z.array(z.string()),
|
|
32
|
+
impact_hints: z.array(z.string()),
|
|
33
|
+
detected_entities: z.array(z.string())
|
|
34
|
+
});
|
|
35
|
+
var _selectionPolicySchema = z.object({
|
|
36
|
+
required_levels: z.tuple([z.literal("L0"), z.literal("L2")]),
|
|
37
|
+
ai_selectable_levels: z.tuple([z.literal("L1")]),
|
|
38
|
+
final_fetch_rule: z.literal("required_stable_ids + ai_selected_l1_stable_ids")
|
|
39
|
+
});
|
|
40
|
+
var planContextInputSchema = z.object({
|
|
41
|
+
paths: z.array(z.string()).min(1).describe("Candidate file paths to build neutral rule selection context for"),
|
|
42
|
+
intent: z.string().optional().describe("User-stated requirement or implementation intent; used only to build a neutral requirement profile"),
|
|
43
|
+
known_tech: z.array(z.string()).optional().describe("Known technologies involved in the requirement profile"),
|
|
44
|
+
detected_entities: z.record(z.array(z.string())).optional().describe("Optional path-keyed detected entities for the requirement profile"),
|
|
45
|
+
client_hash: z.string().optional().describe("Revision hash from a prior fab_plan_context response; enables stale detection"),
|
|
46
|
+
correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
|
|
47
|
+
session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records")
|
|
48
|
+
});
|
|
49
|
+
var planContextOutputSchema = z.object({
|
|
50
|
+
revision_hash: z.string(),
|
|
51
|
+
stale: z.boolean(),
|
|
52
|
+
selection_token: z.string(),
|
|
53
|
+
entries: z.array(
|
|
54
|
+
z.object({
|
|
55
|
+
path: z.string(),
|
|
56
|
+
requirement_profile: _requirementProfileSchema,
|
|
57
|
+
description_index: z.array(_descriptionIndexItemSchema),
|
|
58
|
+
required_stable_ids: z.array(z.string()),
|
|
59
|
+
ai_selectable_stable_ids: z.array(z.string()),
|
|
60
|
+
initial_selected_stable_ids: z.array(z.string()),
|
|
61
|
+
selection_policy: _selectionPolicySchema
|
|
62
|
+
})
|
|
63
|
+
),
|
|
64
|
+
shared: z.object({
|
|
65
|
+
required_stable_ids: z.array(z.string()),
|
|
66
|
+
ai_selectable_stable_ids: z.array(z.string()),
|
|
67
|
+
description_index: z.array(_descriptionIndexItemSchema),
|
|
68
|
+
preflight_diagnostics: z.array(
|
|
69
|
+
z.object({
|
|
70
|
+
code: z.literal("missing_description"),
|
|
71
|
+
severity: z.literal("warn"),
|
|
72
|
+
message: z.string(),
|
|
73
|
+
stable_ids: z.array(z.string()).optional(),
|
|
74
|
+
path: z.string().optional()
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
}),
|
|
78
|
+
warnings: z.array(structuredWarningSchema).optional()
|
|
79
|
+
});
|
|
80
|
+
var planContextAnnotations = {
|
|
81
|
+
readOnlyHint: true,
|
|
82
|
+
idempotentHint: true,
|
|
83
|
+
destructiveHint: false,
|
|
84
|
+
openWorldHint: false,
|
|
85
|
+
title: "Plan rule context"
|
|
86
|
+
};
|
|
87
|
+
var _rulesEntrySchema = z.object({ path: z.string(), content: z.string() });
|
|
88
|
+
var _humanLockedSchema = z.object({ file: z.string(), excerpt: z.string() });
|
|
89
|
+
var _descriptionStubSchema = z.object({ path: z.string(), description: z.string() });
|
|
90
|
+
var getRulesInputSchema = z.object({
|
|
91
|
+
path: z.string().describe("Target file path to query rules for"),
|
|
92
|
+
client_hash: z.string().optional().describe("Revision hash from prior fab_get_rules response; enables stale detection"),
|
|
93
|
+
correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
|
|
94
|
+
session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records")
|
|
95
|
+
});
|
|
96
|
+
var getRulesOutputSchema = z.object({
|
|
97
|
+
revision_hash: z.string(),
|
|
98
|
+
stale: z.boolean(),
|
|
99
|
+
rules: z.object({
|
|
100
|
+
L0: z.string(),
|
|
101
|
+
L1: z.array(_rulesEntrySchema),
|
|
102
|
+
L2: z.array(_rulesEntrySchema),
|
|
103
|
+
human_locked_nearby: z.array(_humanLockedSchema),
|
|
104
|
+
description_stubs: z.array(_descriptionStubSchema).optional()
|
|
105
|
+
}),
|
|
106
|
+
warnings: z.array(structuredWarningSchema).optional()
|
|
107
|
+
});
|
|
108
|
+
var getRulesAnnotations = {
|
|
109
|
+
readOnlyHint: true,
|
|
110
|
+
idempotentHint: true,
|
|
111
|
+
destructiveHint: false,
|
|
112
|
+
openWorldHint: false,
|
|
113
|
+
title: "Get rule content"
|
|
114
|
+
};
|
|
115
|
+
var RULE_SECTION_NAMES_TUPLE = ["MISSION_STATEMENT", "MANDATORY_INJECTION", "BUSINESS_LOGIC_CHUNKS", "CONTEXT_INFO"];
|
|
116
|
+
var ruleSectionsInputSchema = z.object({
|
|
117
|
+
selection_token: z.string().min(1).describe("Selection token returned by fab_plan_context"),
|
|
118
|
+
sections: z.array(z.enum(RULE_SECTION_NAMES_TUPLE)).min(1).describe("Structured rule sections to fetch"),
|
|
119
|
+
ai_selected_stable_ids: z.array(z.string()).describe("AI-selected L1 stable_ids chosen from fab_plan_context ai_selectable_stable_ids"),
|
|
120
|
+
ai_selection_reasons: z.record(z.string().min(1)).describe("Reason for each AI-selected L1 stable_id"),
|
|
121
|
+
correlation_id: z.string().optional().describe("Optional caller-provided correlation id for Event Ledger records"),
|
|
122
|
+
session_id: z.string().optional().describe("Optional caller-provided session id for Event Ledger records")
|
|
123
|
+
});
|
|
124
|
+
var ruleSectionsOutputSchema = z.object({
|
|
125
|
+
revision_hash: z.string(),
|
|
126
|
+
precedence: z.tuple([z.literal("L2"), z.literal("L1"), z.literal("L0")]),
|
|
127
|
+
selected_stable_ids: z.array(z.string()),
|
|
128
|
+
rules: z.array(
|
|
129
|
+
z.object({
|
|
130
|
+
stable_id: z.string(),
|
|
131
|
+
level: z.enum(["L0", "L1", "L2"]),
|
|
132
|
+
path: z.string(),
|
|
133
|
+
sections: z.record(z.string())
|
|
134
|
+
})
|
|
135
|
+
),
|
|
136
|
+
diagnostics: z.array(
|
|
137
|
+
z.object({
|
|
138
|
+
code: z.literal("missing_section"),
|
|
139
|
+
severity: z.literal("warn"),
|
|
140
|
+
stable_id: z.string(),
|
|
141
|
+
section: z.enum(RULE_SECTION_NAMES_TUPLE),
|
|
142
|
+
message: z.string()
|
|
143
|
+
})
|
|
144
|
+
),
|
|
145
|
+
warnings: z.array(structuredWarningSchema).optional()
|
|
146
|
+
});
|
|
147
|
+
var ruleSectionsAnnotations = {
|
|
148
|
+
readOnlyHint: true,
|
|
149
|
+
idempotentHint: true,
|
|
150
|
+
destructiveHint: false,
|
|
151
|
+
openWorldHint: false,
|
|
152
|
+
title: "Filter rule sections"
|
|
153
|
+
};
|
|
154
|
+
var ledgerSourceSchema = z.enum(["ai", "human"]);
|
|
155
|
+
var timestampFilterSchema = z.preprocess((value) => {
|
|
156
|
+
if (value === void 0 || value === null || value === "") {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
if (typeof value === "number") {
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
if (typeof value === "string") {
|
|
163
|
+
const trimmed = value.trim();
|
|
164
|
+
if (trimmed.length === 0) {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
if (/^\d+$/.test(trimmed)) {
|
|
168
|
+
return Number.parseInt(trimmed, 10);
|
|
169
|
+
}
|
|
170
|
+
const parsed = Date.parse(trimmed);
|
|
171
|
+
return Number.isNaN(parsed) ? value : parsed;
|
|
172
|
+
}
|
|
173
|
+
return value;
|
|
174
|
+
}, z.number().int().nonnegative());
|
|
175
|
+
var ledgerQuerySchema = z.object({
|
|
176
|
+
source: ledgerSourceSchema.optional(),
|
|
177
|
+
since: timestampFilterSchema.optional()
|
|
178
|
+
});
|
|
179
|
+
var historyStateQuerySchema = z.object({
|
|
180
|
+
ledger_id: z.string().trim().min(1).optional(),
|
|
181
|
+
ts: timestampFilterSchema.optional()
|
|
182
|
+
}).superRefine((value, ctx) => {
|
|
183
|
+
const provided = [value.ledger_id, value.ts].filter((entry) => entry !== void 0);
|
|
184
|
+
if (provided.length !== 1) {
|
|
185
|
+
ctx.addIssue({
|
|
186
|
+
code: z.ZodIssueCode.custom,
|
|
187
|
+
message: "Provide exactly one of ledger_id or ts.",
|
|
188
|
+
path: ["ledger_id"]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
var humanLockApproveRequestSchema = z.object({
|
|
193
|
+
file: z.string().min(1),
|
|
194
|
+
start_line: z.number().int().positive(),
|
|
195
|
+
end_line: z.number().int().positive(),
|
|
196
|
+
new_hash: z.string().min(1)
|
|
197
|
+
});
|
|
198
|
+
var humanLockFileParamsSchema = z.object({
|
|
199
|
+
file: z.string().min(1)
|
|
200
|
+
});
|
|
201
|
+
var annotateIntentRequestSchema = z.object({
|
|
202
|
+
ledger_entry_id: z.string().min(1),
|
|
203
|
+
annotation: z.string().trim().min(1)
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
export {
|
|
207
|
+
structuredWarningSchema,
|
|
208
|
+
planContextInputSchema,
|
|
209
|
+
planContextOutputSchema,
|
|
210
|
+
planContextAnnotations,
|
|
211
|
+
getRulesInputSchema,
|
|
212
|
+
getRulesOutputSchema,
|
|
213
|
+
getRulesAnnotations,
|
|
214
|
+
ruleSectionsInputSchema,
|
|
215
|
+
ruleSectionsOutputSchema,
|
|
216
|
+
ruleSectionsAnnotations,
|
|
217
|
+
ledgerSourceSchema,
|
|
218
|
+
ledgerQuerySchema,
|
|
219
|
+
historyStateQuerySchema,
|
|
220
|
+
humanLockApproveRequestSchema,
|
|
221
|
+
humanLockFileParamsSchema,
|
|
222
|
+
annotateIntentRequestSchema
|
|
223
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
declare abstract class FabricError extends Error {
|
|
2
|
+
abstract readonly code: string;
|
|
3
|
+
readonly actionHint: string;
|
|
4
|
+
readonly fixable: boolean;
|
|
5
|
+
readonly details?: unknown;
|
|
6
|
+
abstract readonly httpStatus: number;
|
|
7
|
+
constructor(message: string, opts: {
|
|
8
|
+
actionHint: string;
|
|
9
|
+
fixable?: boolean;
|
|
10
|
+
details?: unknown;
|
|
11
|
+
});
|
|
12
|
+
toJSON(): {
|
|
13
|
+
details?: {} | null | undefined;
|
|
14
|
+
name: string;
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
actionHint: string;
|
|
18
|
+
fixable: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare abstract class ConfigError extends FabricError {
|
|
23
|
+
readonly httpStatus = 400;
|
|
24
|
+
}
|
|
25
|
+
declare class ConfigPathInvalidError extends ConfigError {
|
|
26
|
+
readonly code = "config_path_invalid";
|
|
27
|
+
}
|
|
28
|
+
declare class GenericConfigError extends ConfigError {
|
|
29
|
+
readonly code = "config_error";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare abstract class RuleError extends FabricError {
|
|
33
|
+
readonly httpStatus: number;
|
|
34
|
+
}
|
|
35
|
+
declare class RuleValidationError extends RuleError {
|
|
36
|
+
readonly code = "rule_validation_error";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare abstract class IOFabricError extends FabricError {
|
|
40
|
+
readonly httpStatus: number;
|
|
41
|
+
}
|
|
42
|
+
declare class PathEscapeError extends IOFabricError {
|
|
43
|
+
readonly code = "PATH_OUTSIDE_PROJECT_ROOT";
|
|
44
|
+
readonly httpStatus = 403;
|
|
45
|
+
}
|
|
46
|
+
declare class GenericIOError extends IOFabricError {
|
|
47
|
+
readonly code = "io_error";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare abstract class MCPError extends FabricError {
|
|
51
|
+
abstract readonly httpStatus: number;
|
|
52
|
+
}
|
|
53
|
+
declare class McpToolError extends MCPError {
|
|
54
|
+
readonly code = "mcp_tool_error";
|
|
55
|
+
readonly httpStatus = 500;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare abstract class InitError extends FabricError {
|
|
59
|
+
readonly httpStatus = 500;
|
|
60
|
+
}
|
|
61
|
+
declare class InitFrameworkUnknownError extends InitError {
|
|
62
|
+
readonly code = "init_framework_unknown";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ConfigError, ConfigPathInvalidError, FabricError, GenericConfigError, GenericIOError, IOFabricError, InitError, InitFrameworkUnknownError, MCPError, McpToolError, PathEscapeError, RuleError, RuleValidationError };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigError,
|
|
3
|
+
ConfigPathInvalidError,
|
|
4
|
+
FabricError,
|
|
5
|
+
GenericConfigError,
|
|
6
|
+
GenericIOError,
|
|
7
|
+
IOFabricError,
|
|
8
|
+
InitError,
|
|
9
|
+
InitFrameworkUnknownError,
|
|
10
|
+
MCPError,
|
|
11
|
+
McpToolError,
|
|
12
|
+
PathEscapeError,
|
|
13
|
+
RuleError,
|
|
14
|
+
RuleValidationError
|
|
15
|
+
} from "../chunk-3SZRB42B.js";
|
|
16
|
+
export {
|
|
17
|
+
ConfigError,
|
|
18
|
+
ConfigPathInvalidError,
|
|
19
|
+
FabricError,
|
|
20
|
+
GenericConfigError,
|
|
21
|
+
GenericIOError,
|
|
22
|
+
IOFabricError,
|
|
23
|
+
InitError,
|
|
24
|
+
InitFrameworkUnknownError,
|
|
25
|
+
MCPError,
|
|
26
|
+
McpToolError,
|
|
27
|
+
PathEscapeError,
|
|
28
|
+
RuleError,
|
|
29
|
+
RuleValidationError
|
|
30
|
+
};
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare function detectNodeLocale(): Locale;
|
|
|
12
12
|
|
|
13
13
|
declare function normalizeLocale(raw: string | null | undefined): Locale;
|
|
14
14
|
|
|
15
|
-
declare const PROTECTED_TOKENS: readonly ["
|
|
15
|
+
declare const PROTECTED_TOKENS: readonly ["fab_plan_context", "fab_get_rule_sections", "fabric_rules", "ledger_entry", "ledger_entry_id", "agent_meta", "AGENTS.md", "FABRIC.md", ".fabric/agents/", ".fabric/agents/_cross/", ".fabric/agents.meta.json", ".fabric/human-lock.json", ".fabric/init-context.json", ".fabric/forensic.json", ".fabric/.intent-ledger.jsonl", ".fabric/events.jsonl", "@HUMAN", "shadow constraints", "Shadow Mirroring", "CORE RULES", "DO NOT TRANSLATE", "MUST", "NEVER"];
|
|
16
16
|
type ProtectedToken = (typeof PROTECTED_TOKENS)[number];
|
|
17
17
|
|
|
18
18
|
declare const enMessages: Messages;
|