@fenglimg/fabric-shared 1.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,401 @@
1
+ import {
2
+ PROTECTED_TOKENS,
3
+ createTranslator,
4
+ defaultMessages,
5
+ detectNodeLocale,
6
+ enMessages,
7
+ normalizeLocale,
8
+ zhCNMessages
9
+ } from "./chunk-2MXNG23L.js";
10
+ import "./chunk-LXNCAKJZ.js";
11
+
12
+ // src/schemas/agents-meta.ts
13
+ import { z } from "zod";
14
+ var agentsMetaNodeSchema = z.object({
15
+ file: z.string(),
16
+ scope_glob: z.string(),
17
+ deps: z.array(z.string()),
18
+ priority: z.enum(["high", "medium", "low"]),
19
+ hash: z.string()
20
+ });
21
+ var agentsMetaSchema = z.object({
22
+ revision: z.string(),
23
+ nodes: z.record(agentsMetaNodeSchema)
24
+ });
25
+
26
+ // src/schemas/api-contracts.ts
27
+ import { z as z2 } from "zod";
28
+ var ledgerSourceSchema = z2.enum(["ai", "human"]);
29
+ var timestampFilterSchema = z2.preprocess((value) => {
30
+ if (value === void 0 || value === null || value === "") {
31
+ return void 0;
32
+ }
33
+ if (typeof value === "number") {
34
+ return value;
35
+ }
36
+ if (typeof value === "string") {
37
+ const trimmed = value.trim();
38
+ if (trimmed.length === 0) {
39
+ return void 0;
40
+ }
41
+ if (/^\d+$/.test(trimmed)) {
42
+ return Number.parseInt(trimmed, 10);
43
+ }
44
+ const parsed = Date.parse(trimmed);
45
+ return Number.isNaN(parsed) ? value : parsed;
46
+ }
47
+ return value;
48
+ }, z2.number().int().nonnegative());
49
+ var ledgerQuerySchema = z2.object({
50
+ source: ledgerSourceSchema.optional(),
51
+ since: timestampFilterSchema.optional()
52
+ });
53
+ var historyStateQuerySchema = z2.object({
54
+ ledger_id: z2.string().trim().min(1).optional(),
55
+ ts: timestampFilterSchema.optional()
56
+ }).superRefine((value, ctx) => {
57
+ const provided = [value.ledger_id, value.ts].filter((entry) => entry !== void 0);
58
+ if (provided.length !== 1) {
59
+ ctx.addIssue({
60
+ code: z2.ZodIssueCode.custom,
61
+ message: "Provide exactly one of ledger_id or ts.",
62
+ path: ["ledger_id"]
63
+ });
64
+ }
65
+ });
66
+ var humanLockApproveRequestSchema = z2.object({
67
+ file: z2.string().min(1),
68
+ start_line: z2.number().int().positive(),
69
+ end_line: z2.number().int().positive(),
70
+ new_hash: z2.string().min(1)
71
+ });
72
+ var humanLockFileParamsSchema = z2.object({
73
+ file: z2.string().min(1)
74
+ });
75
+ var annotateIntentRequestSchema = z2.object({
76
+ ledger_entry_id: z2.string().min(1),
77
+ annotation: z2.string().trim().min(1)
78
+ });
79
+
80
+ // src/schemas/ledger-entry.ts
81
+ import { z as z3 } from "zod";
82
+ var ledgerEntryBaseSchema = {
83
+ id: z3.string().optional(),
84
+ ts: z3.number().int().nonnegative(),
85
+ intent: z3.string(),
86
+ affected_paths: z3.array(z3.string())
87
+ };
88
+ var aiLedgerEntrySchema = z3.object({
89
+ ...ledgerEntryBaseSchema,
90
+ source: z3.literal("ai"),
91
+ commit_sha: z3.string().optional()
92
+ });
93
+ var humanLedgerEntrySchema = z3.object({
94
+ ...ledgerEntryBaseSchema,
95
+ source: z3.literal("human"),
96
+ parent_sha: z3.string(),
97
+ parent_ledger_entry_id: z3.string().optional(),
98
+ diff_stat: z3.string(),
99
+ annotation: z3.string().optional()
100
+ });
101
+ var ledgerEntryUnionSchema = z3.discriminatedUnion("source", [aiLedgerEntrySchema, humanLedgerEntrySchema]);
102
+ var ledgerEntrySchema = z3.preprocess((value) => {
103
+ if (value && typeof value === "object" && !Array.isArray(value) && (!("source" in value) || value.source === void 0)) {
104
+ return {
105
+ ...value,
106
+ source: "human"
107
+ };
108
+ }
109
+ return value;
110
+ }, ledgerEntryUnionSchema);
111
+
112
+ // src/schemas/human-lock.ts
113
+ import { z as z4 } from "zod";
114
+ var humanLockEntrySchema = z4.object({
115
+ file: z4.string(),
116
+ start_line: z4.number().int().nonnegative(),
117
+ end_line: z4.number().int().nonnegative(),
118
+ hash: z4.string()
119
+ });
120
+ var humanLockFileSchema = z4.object({
121
+ locked: z4.array(humanLockEntrySchema).optional()
122
+ });
123
+
124
+ // src/schemas/fabric-config.ts
125
+ import { z as z5 } from "zod";
126
+ var clientPathsSchema = z5.object({
127
+ claudeCodeCLI: z5.string().optional(),
128
+ claudeCodeDesktop: z5.string().optional(),
129
+ cursor: z5.string().optional(),
130
+ windsurf: z5.string().optional(),
131
+ rooCode: z5.string().optional(),
132
+ geminiCLI: z5.string().optional(),
133
+ codexCLI: z5.string().optional()
134
+ });
135
+ var fabricConfigSchema = z5.object({
136
+ clientPaths: clientPathsSchema.optional(),
137
+ externalFixturePath: z5.string().optional(),
138
+ scanIgnores: z5.array(z5.string()).optional()
139
+ });
140
+
141
+ // src/schemas/forensic-report.ts
142
+ import { z as z6 } from "zod";
143
+ var forensicCodeSampleSchema = z6.object({
144
+ path: z6.string(),
145
+ lines: z6.string(),
146
+ snippet: z6.string(),
147
+ pattern_hint: z6.string()
148
+ });
149
+ var forensicTopologySchema = z6.object({
150
+ total_files: z6.number().int().nonnegative(),
151
+ by_ext: z6.record(z6.number().int().nonnegative()),
152
+ key_dirs: z6.array(z6.string()),
153
+ max_depth: z6.number().int().nonnegative()
154
+ });
155
+ var forensicEntryPointSchema = z6.object({
156
+ path: z6.string(),
157
+ reason: z6.string(),
158
+ size_bytes: z6.number().int().nonnegative().optional()
159
+ });
160
+ var forensicFrameworkSchema = z6.object({
161
+ kind: z6.string(),
162
+ version: z6.string(),
163
+ subkind: z6.string(),
164
+ evidence: z6.array(z6.string())
165
+ });
166
+ var forensicReadmeSchema = z6.object({
167
+ quality: z6.enum(["missing", "stub", "ok"]),
168
+ line_count: z6.number().int().nonnegative(),
169
+ has_contributing: z6.boolean()
170
+ });
171
+ var forensicReportSchema = z6.object({
172
+ version: z6.string(),
173
+ generated_at: z6.string(),
174
+ generated_by: z6.string(),
175
+ target: z6.string(),
176
+ project_name: z6.string(),
177
+ framework: forensicFrameworkSchema,
178
+ topology: forensicTopologySchema,
179
+ entry_points: z6.array(forensicEntryPointSchema),
180
+ code_samples: z6.array(forensicCodeSampleSchema),
181
+ readme: forensicReadmeSchema,
182
+ recommendations_for_skill: z6.array(z6.string())
183
+ });
184
+
185
+ // src/schemas/init-context.ts
186
+ import { z as z7 } from "zod";
187
+ var initContextFrameworkSchema = z7.object({
188
+ kind: z7.string(),
189
+ version: z7.string(),
190
+ subkind: z7.string()
191
+ });
192
+ var initContextInvariantSchema = z7.object({
193
+ type: z7.enum(["ban", "require", "protect"]),
194
+ rule: z7.string(),
195
+ rationale: z7.string().optional()
196
+ });
197
+ var initContextDomainGroupSchema = z7.object({
198
+ name: z7.string(),
199
+ paths: z7.array(z7.string()),
200
+ summary: z7.string().optional()
201
+ });
202
+ var initContextInterviewTrailEntrySchema = z7.object({
203
+ phase: z7.string(),
204
+ question: z7.string(),
205
+ answer: z7.string()
206
+ });
207
+ var initContextSchema = z7.object({
208
+ framework: initContextFrameworkSchema,
209
+ architecture_patterns: z7.array(z7.string()),
210
+ invariants: z7.array(initContextInvariantSchema),
211
+ domain_groups: z7.array(initContextDomainGroupSchema),
212
+ interview_trail: z7.array(initContextInterviewTrailEntrySchema),
213
+ forensic_ref: z7.string()
214
+ });
215
+
216
+ // src/schemas/events.ts
217
+ import { z as z8 } from "zod";
218
+ var metaUpdatedEventSchema = z8.object({
219
+ type: z8.literal("meta:updated"),
220
+ payload: agentsMetaSchema
221
+ });
222
+ var lockDriftEventSchema = z8.object({
223
+ type: z8.literal("lock:drift"),
224
+ payload: z8.object({
225
+ locked: z8.array(humanLockEntrySchema),
226
+ drifted: z8.array(humanLockEntrySchema)
227
+ })
228
+ });
229
+ var lockApprovedEventSchema = z8.object({
230
+ type: z8.literal("lock:approved"),
231
+ payload: z8.object({
232
+ locked: z8.array(humanLockEntrySchema),
233
+ approved: z8.array(humanLockEntrySchema)
234
+ })
235
+ });
236
+ var ledgerAppendedEventSchema = z8.object({
237
+ type: z8.literal("ledger:appended"),
238
+ payload: ledgerEntrySchema
239
+ });
240
+ var driftDetectedEventSchema = z8.object({
241
+ type: z8.literal("drift:detected"),
242
+ payload: forensicReportSchema
243
+ });
244
+ var fabricEventSchema = z8.discriminatedUnion("type", [
245
+ metaUpdatedEventSchema,
246
+ lockDriftEventSchema,
247
+ lockApprovedEventSchema,
248
+ ledgerAppendedEventSchema,
249
+ driftDetectedEventSchema
250
+ ]);
251
+
252
+ // src/detector.ts
253
+ import { existsSync, readFileSync } from "fs";
254
+ import { join } from "path";
255
+ function detectFramework(root) {
256
+ const evidence = [];
257
+ const creatorConfigPath = join(root, "project.config.json");
258
+ if (existsSync(creatorConfigPath)) {
259
+ const version = readCreatorVersion(creatorConfigPath);
260
+ return {
261
+ kind: "cocos-creator",
262
+ version,
263
+ subkind: inferCocosSubkind(root, version),
264
+ evidence: version === "unknown" ? ["project.config.json"] : [`project.config.json: creator.version=${version}`]
265
+ };
266
+ }
267
+ const packageJsonPath = join(root, "package.json");
268
+ if (existsSync(packageJsonPath)) {
269
+ const packageJson = readPackageJson(packageJsonPath);
270
+ const deps = collectDependencyVersions(packageJson);
271
+ for (const [dependencyName, kind] of [
272
+ ["next", "next"],
273
+ ["vite", "vite"],
274
+ ["react", "react"],
275
+ ["vue", "vue"]
276
+ ]) {
277
+ if (deps.has(dependencyName)) {
278
+ const version = deps.get(dependencyName) ?? "unknown";
279
+ evidence.push(`package.json dependency: ${dependencyName}@${version}`);
280
+ return {
281
+ kind,
282
+ version,
283
+ subkind: inferPackageSubkind(kind),
284
+ evidence
285
+ };
286
+ }
287
+ }
288
+ evidence.push("package.json");
289
+ }
290
+ if (existsSync(join(root, "Cargo.toml"))) {
291
+ return {
292
+ kind: "rust",
293
+ version: "unknown",
294
+ subkind: "cargo-project",
295
+ evidence: ["Cargo.toml"]
296
+ };
297
+ }
298
+ if (existsSync(join(root, "pyproject.toml"))) {
299
+ return {
300
+ kind: "python",
301
+ version: "unknown",
302
+ subkind: "pyproject",
303
+ evidence: ["pyproject.toml"]
304
+ };
305
+ }
306
+ return {
307
+ kind: "unknown",
308
+ version: "unknown",
309
+ subkind: "unknown",
310
+ evidence
311
+ };
312
+ }
313
+ function readPackageJson(packageJsonPath) {
314
+ try {
315
+ return JSON.parse(readFileSync(packageJsonPath, "utf8"));
316
+ } catch {
317
+ return {};
318
+ }
319
+ }
320
+ function readCreatorVersion(creatorConfigPath) {
321
+ try {
322
+ const creatorConfig = JSON.parse(readFileSync(creatorConfigPath, "utf8"));
323
+ return creatorConfig.creator?.version ?? "unknown";
324
+ } catch {
325
+ return "unknown";
326
+ }
327
+ }
328
+ function collectDependencyVersions(packageJson) {
329
+ return new Map([
330
+ ...Object.entries(packageJson.dependencies ?? {}),
331
+ ...Object.entries(packageJson.devDependencies ?? {}),
332
+ ...Object.entries(packageJson.peerDependencies ?? {}),
333
+ ...Object.entries(packageJson.optionalDependencies ?? {})
334
+ ]);
335
+ }
336
+ function inferCocosSubkind(root, version) {
337
+ const majorVersion = Number.parseInt(version.split(".")[0] ?? "", 10);
338
+ if (majorVersion === 2) {
339
+ return "javascript-traditional";
340
+ }
341
+ if (majorVersion >= 3) {
342
+ return "typescript-component";
343
+ }
344
+ return existsSync(join(root, "tsconfig.json")) ? "typescript-component" : "javascript-traditional";
345
+ }
346
+ function inferPackageSubkind(kind) {
347
+ switch (kind) {
348
+ case "next":
349
+ return "next-application";
350
+ case "vite":
351
+ return "vite-application";
352
+ case "react":
353
+ return "react-application";
354
+ case "vue":
355
+ return "vue-application";
356
+ default:
357
+ return "unknown";
358
+ }
359
+ }
360
+ export {
361
+ PROTECTED_TOKENS,
362
+ agentsMetaNodeSchema,
363
+ agentsMetaSchema,
364
+ aiLedgerEntrySchema,
365
+ annotateIntentRequestSchema,
366
+ clientPathsSchema,
367
+ createTranslator,
368
+ defaultMessages,
369
+ detectFramework,
370
+ detectNodeLocale,
371
+ driftDetectedEventSchema,
372
+ enMessages,
373
+ fabricConfigSchema,
374
+ fabricEventSchema,
375
+ forensicCodeSampleSchema,
376
+ forensicEntryPointSchema,
377
+ forensicFrameworkSchema,
378
+ forensicReadmeSchema,
379
+ forensicReportSchema,
380
+ forensicTopologySchema,
381
+ historyStateQuerySchema,
382
+ humanLedgerEntrySchema,
383
+ humanLockApproveRequestSchema,
384
+ humanLockEntrySchema,
385
+ humanLockFileParamsSchema,
386
+ humanLockFileSchema,
387
+ initContextDomainGroupSchema,
388
+ initContextFrameworkSchema,
389
+ initContextInterviewTrailEntrySchema,
390
+ initContextInvariantSchema,
391
+ initContextSchema,
392
+ ledgerAppendedEventSchema,
393
+ ledgerEntrySchema,
394
+ ledgerQuerySchema,
395
+ ledgerSourceSchema,
396
+ lockApprovedEventSchema,
397
+ lockDriftEventSchema,
398
+ metaUpdatedEventSchema,
399
+ normalizeLocale,
400
+ zhCNMessages
401
+ };
@@ -0,0 +1,55 @@
1
+ interface AgentsMetaNode {
2
+ file: string;
3
+ scope_glob: string;
4
+ deps: string[];
5
+ priority: "high" | "medium" | "low";
6
+ hash: string;
7
+ }
8
+ interface AgentsMeta {
9
+ revision: string;
10
+ nodes: Record<string, AgentsMetaNode>;
11
+ }
12
+
13
+ interface AiLedgerEntry {
14
+ id?: string;
15
+ ts: number;
16
+ source: "ai";
17
+ commit_sha?: string;
18
+ intent: string;
19
+ affected_paths: string[];
20
+ }
21
+ interface HumanLedgerEntry {
22
+ id?: string;
23
+ ts: number;
24
+ source: "human";
25
+ parent_sha: string;
26
+ parent_ledger_entry_id?: string;
27
+ intent: string;
28
+ affected_paths: string[];
29
+ diff_stat: string;
30
+ annotation?: string;
31
+ }
32
+ type LedgerEntry = AiLedgerEntry | HumanLedgerEntry;
33
+ interface HumanLockEntry {
34
+ file: string;
35
+ start_line: number;
36
+ end_line: number;
37
+ hash: string;
38
+ }
39
+
40
+ interface ClientPaths {
41
+ claudeCodeCLI?: string;
42
+ claudeCodeDesktop?: string;
43
+ cursor?: string;
44
+ windsurf?: string;
45
+ rooCode?: string;
46
+ geminiCLI?: string;
47
+ codexCLI?: string;
48
+ }
49
+ interface FabricConfig {
50
+ clientPaths?: ClientPaths;
51
+ externalFixturePath?: string;
52
+ scanIgnores?: string[];
53
+ }
54
+
55
+ export type { AgentsMeta, AgentsMetaNode, AiLedgerEntry, ClientPaths, FabricConfig, HumanLedgerEntry, HumanLockEntry, LedgerEntry };
@@ -0,0 +1 @@
1
+ import "../chunk-LXNCAKJZ.js";
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@fenglimg/fabric-shared",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./i18n": {
13
+ "types": "./dist/i18n/index.d.ts",
14
+ "import": "./dist/i18n/index.js"
15
+ },
16
+ "./types": {
17
+ "types": "./dist/types/index.d.ts",
18
+ "import": "./dist/types/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "zod": "^3.25.0"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.5.0",
29
+ "typescript": "^5.8.3"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup src/index.ts src/i18n/index.ts src/types/index.ts --format esm --dts --clean",
33
+ "dev": "tsup src/index.ts src/i18n/index.ts src/types/index.ts --format esm --dts --watch"
34
+ }
35
+ }