@fenglimg/fabric-cli 0.1.4 → 1.1.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.
Files changed (31) hide show
  1. package/dist/{bootstrap-HUDJ2E3Q.js → bootstrap-PMIA4W6G.js} +16 -12
  2. package/dist/chunk-6ICJICVU.js +10 -0
  3. package/dist/{chunk-T3WQUWW4.js → chunk-6UUPKSDE.js} +78 -36
  4. package/dist/chunk-AEOYCVBG.js +0 -0
  5. package/dist/{chunk-U376IPKT.js → chunk-F2BXHPM5.js} +11 -7
  6. package/dist/chunk-JWUO6TIS.js +220 -0
  7. package/dist/{chunk-CZ7U6ULM.js → chunk-L43IGJ6X.js} +17 -7
  8. package/dist/{chunk-N7TTCGJA.js → chunk-VMYPJPKV.js} +1 -0
  9. package/dist/chunk-WWNXR34K.js +49 -0
  10. package/dist/{config-YKDWIRCT.js → config-PXEEXWLM.js} +14 -11
  11. package/dist/doctor-QTSG2RWF.js +125 -0
  12. package/dist/{hooks-VXXO4VZP.js → hooks-5S5IRVQE.js} +15 -12
  13. package/dist/human-lint-YSFOZHZ7.js +13 -0
  14. package/dist/index.js +16 -11
  15. package/dist/init-R73E5YTG.js +1164 -0
  16. package/dist/{ledger-append-EGIKSMU5.js → ledger-append-XZ5SX4O5.js} +2 -1
  17. package/dist/{pre-commit-CXPH7BZH.js → pre-commit-BLSUMT3P.js} +14 -9
  18. package/dist/{scan-UASZQLQP.js → scan-JBGFRB7P.js} +3 -2
  19. package/dist/serve-4J2CQY25.js +112 -0
  20. package/dist/{sync-meta-YTG5V3Y6.js → sync-meta-THZSEM7Y.js} +6 -2
  21. package/package.json +12 -8
  22. package/templates/agents-md/AGENTS.md.template +20 -29
  23. package/templates/agents-md/variants/cocos.md +20 -0
  24. package/templates/agents-md/variants/next.md +20 -0
  25. package/templates/agents-md/variants/vite.md +20 -0
  26. package/templates/claude-hooks/agents-md-init-reminder.cjs +18 -0
  27. package/templates/claude-skills/agents-md-init/SKILL.md +86 -0
  28. package/dist/chunk-BWZHNZG6.js +0 -236
  29. package/dist/chunk-P4KVFB2T.js +0 -22
  30. package/dist/human-lint-II6TBGP4.js +0 -9
  31. package/dist/init-IBS7KO7A.js +0 -149
@@ -1,236 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- createDebugLogger,
4
- readFabricConfig,
5
- resolveDevMode
6
- } from "./chunk-AEOYCVBG.js";
7
- import {
8
- resolveIgnores
9
- } from "./chunk-P4KVFB2T.js";
10
-
11
- // src/commands/scan.ts
12
- import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
13
- import { isAbsolute, join as join2, relative, resolve, sep } from "path";
14
- import { defineCommand } from "citty";
15
-
16
- // src/scanner/detector.ts
17
- import { existsSync, readFileSync } from "fs";
18
- import { join } from "path";
19
- function detectFramework(root) {
20
- const evidence = [];
21
- if (existsSync(join(root, "project.config.json"))) {
22
- return {
23
- kind: "cocos-creator",
24
- evidence: ["project.config.json"]
25
- };
26
- }
27
- const packageJsonPath = join(root, "package.json");
28
- if (existsSync(packageJsonPath)) {
29
- const packageJson = readPackageJson(packageJsonPath);
30
- const deps = collectDependencyNames(packageJson);
31
- for (const [dependencyName, kind] of [
32
- ["next", "next"],
33
- ["vite", "vite"],
34
- ["react", "react"],
35
- ["vue", "vue"]
36
- ]) {
37
- if (deps.has(dependencyName)) {
38
- evidence.push(`package.json dependency: ${dependencyName}`);
39
- return { kind, evidence };
40
- }
41
- }
42
- evidence.push("package.json");
43
- }
44
- if (existsSync(join(root, "Cargo.toml"))) {
45
- return {
46
- kind: "rust",
47
- evidence: ["Cargo.toml"]
48
- };
49
- }
50
- if (existsSync(join(root, "pyproject.toml"))) {
51
- return {
52
- kind: "python",
53
- evidence: ["pyproject.toml"]
54
- };
55
- }
56
- return {
57
- kind: "unknown",
58
- evidence
59
- };
60
- }
61
- function readPackageJson(packageJsonPath) {
62
- try {
63
- return JSON.parse(readFileSync(packageJsonPath, "utf8"));
64
- } catch {
65
- return {};
66
- }
67
- }
68
- function collectDependencyNames(packageJson) {
69
- return /* @__PURE__ */ new Set([
70
- ...Object.keys(packageJson.dependencies ?? {}),
71
- ...Object.keys(packageJson.devDependencies ?? {}),
72
- ...Object.keys(packageJson.peerDependencies ?? {}),
73
- ...Object.keys(packageJson.optionalDependencies ?? {})
74
- ]);
75
- }
76
-
77
- // src/commands/scan.ts
78
- function createScanReport(targetInput = process.cwd(), fabricConfig) {
79
- const target = normalizeTarget(targetInput);
80
- const framework = detectFramework(target);
81
- const readmeQuality = getReadmeQuality(target);
82
- const hasContributing = existsSync2(join2(target, "CONTRIBUTING.md"));
83
- const hasExistingFabric = existsSync2(join2(target, "AGENTS.md")) || existsSync2(join2(target, ".fabric"));
84
- const walkResult = walkFiles(target, resolveIgnores(fabricConfig));
85
- return {
86
- target,
87
- framework,
88
- readmeQuality,
89
- hasContributing,
90
- fileCount: walkResult.fileCount,
91
- ignoredCount: walkResult.ignoredCount,
92
- hasExistingFabric,
93
- recommendations: buildRecommendations({
94
- framework,
95
- readmeQuality,
96
- hasContributing,
97
- hasExistingFabric
98
- })
99
- };
100
- }
101
- var scanCommand = defineCommand({
102
- meta: {
103
- name: "scan",
104
- description: "\u626B\u63CF\u9879\u76EE\u4EE5\u68C0\u6D4B Fabric \u5F15\u5BFC\u5019\u9009\u6A21\u5757\u3002"
105
- },
106
- args: {
107
- target: {
108
- type: "string",
109
- description: "\u626B\u63CF\u7684\u76EE\u6807\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u4F9D\u6B21\u4F7F\u7528 CLI \u53C2\u6570\u3001EXTERNAL_FIXTURE_PATH\u3001fabric.config.json \u6216\u5F53\u524D\u76EE\u5F55\u3002"
110
- },
111
- debug: {
112
- type: "boolean",
113
- description: "\u4EE5\u683C\u5F0F\u5316\u8F93\u51FA\u6253\u5370\u68C0\u6D4B\u8BC1\u636E\u3002",
114
- default: false
115
- },
116
- json: {
117
- type: "boolean",
118
- description: "\u4EE5 JSON \u683C\u5F0F\u8F93\u51FA\u8BCA\u65AD\u62A5\u544A\u3002",
119
- default: false
120
- }
121
- },
122
- async run({ args }) {
123
- const workspaceRoot = process.cwd();
124
- const logger = createDebugLogger(args.debug);
125
- const resolution = resolveDevMode(args.target, workspaceRoot);
126
- const fabricConfig = readFabricConfig(workspaceRoot);
127
- logger(`scan target source: ${resolution.source}`);
128
- for (const step of resolution.chain) {
129
- logger(step);
130
- }
131
- const report = createScanReport(resolution.target, fabricConfig);
132
- if (args.json) {
133
- console.log(JSON.stringify(report, null, 2));
134
- return;
135
- }
136
- printPrettyReport(report, Boolean(args.debug));
137
- }
138
- });
139
- var scan_default = scanCommand;
140
- function normalizeTarget(targetInput) {
141
- return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
142
- }
143
- function getReadmeQuality(target) {
144
- const readmePath = join2(target, "README.md");
145
- if (!existsSync2(readmePath)) {
146
- return "stub";
147
- }
148
- const wordCount = readFileSync2(readmePath, "utf8").trim().split(/\s+/).filter(Boolean).length;
149
- return wordCount >= 200 ? "ok" : "stub";
150
- }
151
- function walkFiles(root, ignorePatterns) {
152
- if (!existsSync2(root) || !statSync(root).isDirectory()) {
153
- throw new Error(`Target must be an existing directory: ${root}`);
154
- }
155
- let fileCount = 0;
156
- let ignoredCount = 0;
157
- const stack = [root];
158
- while (stack.length > 0) {
159
- const current = stack.pop();
160
- if (current === void 0) {
161
- continue;
162
- }
163
- for (const entry of readdirSync(current, { withFileTypes: true })) {
164
- const absolutePath = join2(current, entry.name);
165
- const relativePath = toPosixPath(relative(root, absolutePath));
166
- if (shouldIgnore(relativePath, entry.isDirectory(), ignorePatterns)) {
167
- ignoredCount += 1;
168
- continue;
169
- }
170
- if (entry.isDirectory()) {
171
- stack.push(absolutePath);
172
- } else if (entry.isFile()) {
173
- fileCount += 1;
174
- }
175
- }
176
- }
177
- return { fileCount, ignoredCount };
178
- }
179
- function shouldIgnore(relativePath, isDirectory, ignorePatterns) {
180
- return ignorePatterns.some((pattern) => matchesIgnorePattern(relativePath, isDirectory, pattern));
181
- }
182
- function matchesIgnorePattern(relativePath, isDirectory, pattern) {
183
- const normalizedPattern = toPosixPath(pattern);
184
- if (normalizedPattern === "**/*.meta") {
185
- return relativePath.endsWith(".meta");
186
- }
187
- if (normalizedPattern.endsWith("/**")) {
188
- const directoryPrefix = normalizedPattern.slice(0, -3);
189
- return relativePath === directoryPrefix || relativePath.startsWith(`${directoryPrefix}/`) || isDirectory && `${relativePath}/` === directoryPrefix;
190
- }
191
- return relativePath === normalizedPattern;
192
- }
193
- function toPosixPath(path) {
194
- return path.split(sep).join("/");
195
- }
196
- function buildRecommendations(input) {
197
- const recommendations = [];
198
- if (!input.hasExistingFabric) {
199
- recommendations.push("L0: Run fab init to scaffold AGENTS.md with TODO markers.");
200
- }
201
- if (input.readmeQuality === "stub") {
202
- recommendations.push("L0: Expand README.md before promoting project facts into AGENTS.md references.");
203
- }
204
- if (!input.hasContributing) {
205
- recommendations.push("L0: Add CONTRIBUTING.md or leave an AGENTS.md TODO reference for contribution flow.");
206
- }
207
- if (input.framework.kind === "unknown") {
208
- recommendations.push("L1: Add tech-stack TODOs manually because no framework marker was detected.");
209
- } else {
210
- recommendations.push(`L1: Review ${input.framework.kind} directories for future scoped AGENTS.md files.`);
211
- }
212
- return recommendations;
213
- }
214
- function printPrettyReport(report, debug) {
215
- console.log("Fabric scan report");
216
- console.log(`Target: ${report.target}`);
217
- console.log(`Framework: ${report.framework.kind}`);
218
- if (debug) {
219
- console.log(`Evidence: ${report.framework.evidence.length > 0 ? report.framework.evidence.join(", ") : "none"}`);
220
- }
221
- console.log(`README quality: ${report.readmeQuality}`);
222
- console.log(`CONTRIBUTING.md: ${report.hasContributing ? "present" : "missing"}`);
223
- console.log(`Files counted: ${report.fileCount}`);
224
- console.log(`Ignored entries: ${report.ignoredCount}`);
225
- console.log(`Existing Fabric files: ${report.hasExistingFabric ? "yes" : "no"}`);
226
- console.log("Recommendations:");
227
- for (const recommendation of report.recommendations) {
228
- console.log(`- ${recommendation}`);
229
- }
230
- }
231
-
232
- export {
233
- createScanReport,
234
- scanCommand,
235
- scan_default
236
- };
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/scanner/ignores.ts
4
- var DEFAULT_IGNORES = [
5
- "**/*.meta",
6
- "library/**",
7
- "temp/**",
8
- "build/**",
9
- "settings/**",
10
- "profiles/**",
11
- "node_modules/**",
12
- "dist/**",
13
- ".git/**",
14
- ".fabric/**"
15
- ];
16
- function resolveIgnores(fabricConfig) {
17
- return [...DEFAULT_IGNORES, ...fabricConfig?.scanIgnores ?? []];
18
- }
19
-
20
- export {
21
- resolveIgnores
22
- };
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- humanLintCommand,
4
- human_lint_default
5
- } from "./chunk-CZ7U6ULM.js";
6
- export {
7
- human_lint_default as default,
8
- humanLintCommand
9
- };
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- createScanReport
4
- } from "./chunk-BWZHNZG6.js";
5
- import {
6
- createDebugLogger,
7
- resolveDevMode
8
- } from "./chunk-AEOYCVBG.js";
9
- import "./chunk-P4KVFB2T.js";
10
-
11
- // src/commands/init.ts
12
- import { createHash } from "crypto";
13
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
14
- import { dirname, isAbsolute, join, parse, resolve } from "path";
15
- import { fileURLToPath } from "url";
16
- import { defineCommand } from "citty";
17
- var initCommand = defineCommand({
18
- meta: {
19
- name: "init",
20
- description: "\u5728\u76EE\u6807\u9879\u76EE\u4E2D\u521D\u59CB\u5316 Fabric\u3002"
21
- },
22
- args: {
23
- target: {
24
- type: "string",
25
- description: "\u76EE\u6807\u9879\u76EE\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u4F9D\u6B21\u4F7F\u7528 CLI \u53C2\u6570\u3001EXTERNAL_FIXTURE_PATH\u3001fabric.config.json \u6216\u5F53\u524D\u76EE\u5F55\u3002"
26
- },
27
- debug: {
28
- type: "boolean",
29
- description: "\u5C06\u76EE\u6807\u89E3\u6790\u8BE6\u60C5\u8F93\u51FA\u5230 stderr\u3002",
30
- default: false
31
- }
32
- },
33
- async run({ args }) {
34
- const logger = createDebugLogger(args.debug);
35
- const resolution = resolveDevMode(args.target, process.cwd());
36
- const target = normalizeTarget(resolution.target);
37
- logger(`init target source: ${resolution.source}`);
38
- for (const step of resolution.chain) {
39
- logger(step);
40
- }
41
- const created = initFabric(target);
42
- console.log(`Created ${created.agentsPath}`);
43
- console.log(`Created ${created.metaPath}`);
44
- console.log(`Created ${created.humanLockPath}`);
45
- console.log("Next: run fab hooks install to add the Day 4 pre-commit pipeline.");
46
- }
47
- });
48
- var init_default = initCommand;
49
- function initFabric(target) {
50
- assertExistingDirectory(target);
51
- const agentsPath = join(target, "AGENTS.md");
52
- const fabricDir = join(target, ".fabric");
53
- if (existsSync(agentsPath)) {
54
- throw new Error(`ABORT: ${agentsPath} already exists. fab init is non-destructive.`);
55
- }
56
- if (existsSync(fabricDir)) {
57
- throw new Error(`ABORT: ${fabricDir} already exists. fab init is non-destructive.`);
58
- }
59
- const scanReport = createScanReport(target);
60
- const template = readFileSync(findTemplatePath("templates/agents-md/AGENTS.md.template"), "utf8");
61
- const humanLockTemplate = readFileSync(findTemplatePath("templates/fabric/human-lock.json"), "utf8");
62
- const packageName = readPackageName(target) ?? "// TODO: project name";
63
- const agentsContent = template.replaceAll("{ projectName }", packageName).replaceAll("{ frameworkKind }", scanReport.framework.kind);
64
- const agentsHash = sha256(agentsContent);
65
- const meta = createInitialMeta(agentsHash);
66
- const metaPath = join(fabricDir, "agents.meta.json");
67
- const humanLockPath = join(fabricDir, "human-lock.json");
68
- mkdirSync(fabricDir, { recursive: false });
69
- writeNewFile(agentsPath, agentsContent);
70
- writeNewFile(metaPath, `${JSON.stringify(meta, null, 2)}
71
- `);
72
- writeNewFile(humanLockPath, humanLockTemplate.endsWith("\n") ? humanLockTemplate : `${humanLockTemplate}
73
- `);
74
- return { agentsPath, metaPath, humanLockPath };
75
- }
76
- function normalizeTarget(targetInput) {
77
- return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
78
- }
79
- function assertExistingDirectory(target) {
80
- if (!existsSync(target) || !statSync(target).isDirectory()) {
81
- throw new Error(`Target must be an existing directory: ${target}`);
82
- }
83
- }
84
- function createInitialMeta(agentsHash) {
85
- return {
86
- revision: sha256(agentsHash),
87
- nodes: {
88
- L0: {
89
- file: "AGENTS.md",
90
- scope_glob: "**",
91
- deps: [],
92
- priority: "high",
93
- hash: agentsHash
94
- }
95
- }
96
- };
97
- }
98
- function readPackageName(target) {
99
- const packageJsonPath = join(target, "package.json");
100
- if (!existsSync(packageJsonPath)) {
101
- return void 0;
102
- }
103
- try {
104
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
105
- return packageJson.name;
106
- } catch {
107
- return void 0;
108
- }
109
- }
110
- function findTemplatePath(relativePath) {
111
- const currentModuleDir = dirname(fileURLToPath(import.meta.url));
112
- const candidates = [
113
- ...templateCandidatesFrom(process.cwd(), relativePath),
114
- ...templateCandidatesFrom(currentModuleDir, relativePath)
115
- ];
116
- for (const candidate of candidates) {
117
- if (existsSync(candidate)) {
118
- return candidate;
119
- }
120
- }
121
- throw new Error(`Template not found: ${relativePath}`);
122
- }
123
- function templateCandidatesFrom(start, relativePath) {
124
- const candidates = [];
125
- let current = resolve(start);
126
- while (true) {
127
- candidates.push(join(current, ...relativePath.split("/")));
128
- const parent = dirname(current);
129
- if (parent === current || parse(current).root === current) {
130
- break;
131
- }
132
- current = parent;
133
- }
134
- return candidates;
135
- }
136
- function writeNewFile(path, content) {
137
- if (existsSync(path)) {
138
- throw new Error(`ABORT: ${path} already exists. fab init is non-destructive.`);
139
- }
140
- writeFileSync(path, content, "utf8");
141
- }
142
- function sha256(content) {
143
- return `sha256:${createHash("sha256").update(content).digest("hex")}`;
144
- }
145
- export {
146
- init_default as default,
147
- initCommand,
148
- initFabric
149
- };