@fenglimg/fabric-cli 0.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.
@@ -0,0 +1,235 @@
1
+ import {
2
+ createDebugLogger,
3
+ readFabricConfig,
4
+ resolveDevMode
5
+ } from "./chunk-JLIIQ75E.js";
6
+ import {
7
+ resolveIgnores
8
+ } from "./chunk-ZTNSMODH.js";
9
+
10
+ // src/commands/scan.ts
11
+ import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
12
+ import { isAbsolute, join as join2, relative, resolve, sep } from "path";
13
+ import { defineCommand } from "citty";
14
+
15
+ // src/scanner/detector.ts
16
+ import { existsSync, readFileSync } from "fs";
17
+ import { join } from "path";
18
+ function detectFramework(root) {
19
+ const evidence = [];
20
+ if (existsSync(join(root, "project.config.json"))) {
21
+ return {
22
+ kind: "cocos-creator",
23
+ evidence: ["project.config.json"]
24
+ };
25
+ }
26
+ const packageJsonPath = join(root, "package.json");
27
+ if (existsSync(packageJsonPath)) {
28
+ const packageJson = readPackageJson(packageJsonPath);
29
+ const deps = collectDependencyNames(packageJson);
30
+ for (const [dependencyName, kind] of [
31
+ ["next", "next"],
32
+ ["vite", "vite"],
33
+ ["react", "react"],
34
+ ["vue", "vue"]
35
+ ]) {
36
+ if (deps.has(dependencyName)) {
37
+ evidence.push(`package.json dependency: ${dependencyName}`);
38
+ return { kind, evidence };
39
+ }
40
+ }
41
+ evidence.push("package.json");
42
+ }
43
+ if (existsSync(join(root, "Cargo.toml"))) {
44
+ return {
45
+ kind: "rust",
46
+ evidence: ["Cargo.toml"]
47
+ };
48
+ }
49
+ if (existsSync(join(root, "pyproject.toml"))) {
50
+ return {
51
+ kind: "python",
52
+ evidence: ["pyproject.toml"]
53
+ };
54
+ }
55
+ return {
56
+ kind: "unknown",
57
+ evidence
58
+ };
59
+ }
60
+ function readPackageJson(packageJsonPath) {
61
+ try {
62
+ return JSON.parse(readFileSync(packageJsonPath, "utf8"));
63
+ } catch {
64
+ return {};
65
+ }
66
+ }
67
+ function collectDependencyNames(packageJson) {
68
+ return /* @__PURE__ */ new Set([
69
+ ...Object.keys(packageJson.dependencies ?? {}),
70
+ ...Object.keys(packageJson.devDependencies ?? {}),
71
+ ...Object.keys(packageJson.peerDependencies ?? {}),
72
+ ...Object.keys(packageJson.optionalDependencies ?? {})
73
+ ]);
74
+ }
75
+
76
+ // src/commands/scan.ts
77
+ function createScanReport(targetInput = process.cwd(), fabricConfig) {
78
+ const target = normalizeTarget(targetInput);
79
+ const framework = detectFramework(target);
80
+ const readmeQuality = getReadmeQuality(target);
81
+ const hasContributing = existsSync2(join2(target, "CONTRIBUTING.md"));
82
+ const hasExistingFabric = existsSync2(join2(target, "AGENTS.md")) || existsSync2(join2(target, ".fabric"));
83
+ const walkResult = walkFiles(target, resolveIgnores(fabricConfig));
84
+ return {
85
+ target,
86
+ framework,
87
+ readmeQuality,
88
+ hasContributing,
89
+ fileCount: walkResult.fileCount,
90
+ ignoredCount: walkResult.ignoredCount,
91
+ hasExistingFabric,
92
+ recommendations: buildRecommendations({
93
+ framework,
94
+ readmeQuality,
95
+ hasContributing,
96
+ hasExistingFabric
97
+ })
98
+ };
99
+ }
100
+ var scanCommand = defineCommand({
101
+ meta: {
102
+ name: "scan",
103
+ description: "Scan a project for Fabric bootstrap candidates."
104
+ },
105
+ args: {
106
+ target: {
107
+ type: "string",
108
+ description: "Absolute target path to scan. Defaults to CLI target, EXTERNAL_FIXTURE_PATH, fabric.config.json, or cwd."
109
+ },
110
+ debug: {
111
+ type: "boolean",
112
+ description: "Print detector evidence in pretty output.",
113
+ default: false
114
+ },
115
+ json: {
116
+ type: "boolean",
117
+ description: "Print the diagnostic report as JSON.",
118
+ default: false
119
+ }
120
+ },
121
+ async run({ args }) {
122
+ const workspaceRoot = process.cwd();
123
+ const logger = createDebugLogger(args.debug);
124
+ const resolution = resolveDevMode(args.target, workspaceRoot);
125
+ const fabricConfig = readFabricConfig(workspaceRoot);
126
+ logger(`scan target source: ${resolution.source}`);
127
+ for (const step of resolution.chain) {
128
+ logger(step);
129
+ }
130
+ const report = createScanReport(resolution.target, fabricConfig);
131
+ if (args.json) {
132
+ console.log(JSON.stringify(report, null, 2));
133
+ return;
134
+ }
135
+ printPrettyReport(report, Boolean(args.debug));
136
+ }
137
+ });
138
+ var scan_default = scanCommand;
139
+ function normalizeTarget(targetInput) {
140
+ return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
141
+ }
142
+ function getReadmeQuality(target) {
143
+ const readmePath = join2(target, "README.md");
144
+ if (!existsSync2(readmePath)) {
145
+ return "stub";
146
+ }
147
+ const wordCount = readFileSync2(readmePath, "utf8").trim().split(/\s+/).filter(Boolean).length;
148
+ return wordCount >= 200 ? "ok" : "stub";
149
+ }
150
+ function walkFiles(root, ignorePatterns) {
151
+ if (!existsSync2(root) || !statSync(root).isDirectory()) {
152
+ throw new Error(`Target must be an existing directory: ${root}`);
153
+ }
154
+ let fileCount = 0;
155
+ let ignoredCount = 0;
156
+ const stack = [root];
157
+ while (stack.length > 0) {
158
+ const current = stack.pop();
159
+ if (current === void 0) {
160
+ continue;
161
+ }
162
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
163
+ const absolutePath = join2(current, entry.name);
164
+ const relativePath = toPosixPath(relative(root, absolutePath));
165
+ if (shouldIgnore(relativePath, entry.isDirectory(), ignorePatterns)) {
166
+ ignoredCount += 1;
167
+ continue;
168
+ }
169
+ if (entry.isDirectory()) {
170
+ stack.push(absolutePath);
171
+ } else if (entry.isFile()) {
172
+ fileCount += 1;
173
+ }
174
+ }
175
+ }
176
+ return { fileCount, ignoredCount };
177
+ }
178
+ function shouldIgnore(relativePath, isDirectory, ignorePatterns) {
179
+ return ignorePatterns.some((pattern) => matchesIgnorePattern(relativePath, isDirectory, pattern));
180
+ }
181
+ function matchesIgnorePattern(relativePath, isDirectory, pattern) {
182
+ const normalizedPattern = toPosixPath(pattern);
183
+ if (normalizedPattern === "**/*.meta") {
184
+ return relativePath.endsWith(".meta");
185
+ }
186
+ if (normalizedPattern.endsWith("/**")) {
187
+ const directoryPrefix = normalizedPattern.slice(0, -3);
188
+ return relativePath === directoryPrefix || relativePath.startsWith(`${directoryPrefix}/`) || isDirectory && `${relativePath}/` === directoryPrefix;
189
+ }
190
+ return relativePath === normalizedPattern;
191
+ }
192
+ function toPosixPath(path) {
193
+ return path.split(sep).join("/");
194
+ }
195
+ function buildRecommendations(input) {
196
+ const recommendations = [];
197
+ if (!input.hasExistingFabric) {
198
+ recommendations.push("L0: Run fab init to scaffold AGENTS.md with TODO markers.");
199
+ }
200
+ if (input.readmeQuality === "stub") {
201
+ recommendations.push("L0: Expand README.md before promoting project facts into AGENTS.md references.");
202
+ }
203
+ if (!input.hasContributing) {
204
+ recommendations.push("L0: Add CONTRIBUTING.md or leave an AGENTS.md TODO reference for contribution flow.");
205
+ }
206
+ if (input.framework.kind === "unknown") {
207
+ recommendations.push("L1: Add tech-stack TODOs manually because no framework marker was detected.");
208
+ } else {
209
+ recommendations.push(`L1: Review ${input.framework.kind} directories for future scoped AGENTS.md files.`);
210
+ }
211
+ return recommendations;
212
+ }
213
+ function printPrettyReport(report, debug) {
214
+ console.log("Fabric scan report");
215
+ console.log(`Target: ${report.target}`);
216
+ console.log(`Framework: ${report.framework.kind}`);
217
+ if (debug) {
218
+ console.log(`Evidence: ${report.framework.evidence.length > 0 ? report.framework.evidence.join(", ") : "none"}`);
219
+ }
220
+ console.log(`README quality: ${report.readmeQuality}`);
221
+ console.log(`CONTRIBUTING.md: ${report.hasContributing ? "present" : "missing"}`);
222
+ console.log(`Files counted: ${report.fileCount}`);
223
+ console.log(`Ignored entries: ${report.ignoredCount}`);
224
+ console.log(`Existing Fabric files: ${report.hasExistingFabric ? "yes" : "no"}`);
225
+ console.log("Recommendations:");
226
+ for (const recommendation of report.recommendations) {
227
+ console.log(`- ${recommendation}`);
228
+ }
229
+ }
230
+
231
+ export {
232
+ createScanReport,
233
+ scanCommand,
234
+ scan_default
235
+ };
@@ -0,0 +1,20 @@
1
+ // src/scanner/ignores.ts
2
+ var DEFAULT_IGNORES = [
3
+ "**/*.meta",
4
+ "library/**",
5
+ "temp/**",
6
+ "build/**",
7
+ "settings/**",
8
+ "profiles/**",
9
+ "node_modules/**",
10
+ "dist/**",
11
+ ".git/**",
12
+ ".fabric/**"
13
+ ];
14
+ function resolveIgnores(fabricConfig) {
15
+ return [...DEFAULT_IGNORES, ...fabricConfig?.scanIgnores ?? []];
16
+ }
17
+
18
+ export {
19
+ resolveIgnores
20
+ };
@@ -0,0 +1,119 @@
1
+ import {
2
+ resolveClients
3
+ } from "./chunk-LHPBYOF5.js";
4
+
5
+ // src/commands/config.ts
6
+ import { existsSync } from "fs";
7
+ import { readFile } from "fs/promises";
8
+ import { resolve } from "path";
9
+ import { fileURLToPath } from "url";
10
+ import { defineCommand } from "citty";
11
+ var CLIENT_ALIASES = {
12
+ claudecodecli: "ClaudeCodeCLI",
13
+ "claude-code-cli": "ClaudeCodeCLI",
14
+ claudecli: "ClaudeCodeCLI",
15
+ claudecodedesktop: "ClaudeCodeDesktop",
16
+ "claude-code-desktop": "ClaudeCodeDesktop",
17
+ claudedesktop: "ClaudeCodeDesktop",
18
+ cursor: "Cursor",
19
+ windsurf: "Windsurf",
20
+ roocode: "RooCode",
21
+ "roo-code": "RooCode",
22
+ roo: "RooCode",
23
+ geminicli: "GeminiCLI",
24
+ "gemini-cli": "GeminiCLI",
25
+ gemini: "GeminiCLI",
26
+ codexcli: "CodexCLI",
27
+ "codex-cli": "CodexCLI",
28
+ codex: "CodexCLI"
29
+ };
30
+ function parseClientFilter(value) {
31
+ if (value === void 0 || value.trim().length === 0) {
32
+ return null;
33
+ }
34
+ const clients = /* @__PURE__ */ new Set();
35
+ for (const rawClient of value.split(",")) {
36
+ const alias = rawClient.trim().toLowerCase();
37
+ const clientKind = CLIENT_ALIASES[alias];
38
+ if (clientKind === void 0) {
39
+ throw new Error(`Unknown client "${rawClient}". Use a comma-separated list such as cursor,codex,gemini.`);
40
+ }
41
+ clients.add(clientKind);
42
+ }
43
+ return clients;
44
+ }
45
+ async function loadFabricConfig(workspaceRoot) {
46
+ const configPath = resolve(workspaceRoot, "fabric.config.json");
47
+ if (!existsSync(configPath)) {
48
+ return {};
49
+ }
50
+ const parsed = JSON.parse(await readFile(configPath, "utf8"));
51
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
52
+ throw new Error(`Expected object in ${configPath}`);
53
+ }
54
+ return parsed;
55
+ }
56
+ function resolveServerPath() {
57
+ if (process.env.FAB_SERVER_PATH) return resolve(process.env.FAB_SERVER_PATH);
58
+ return fileURLToPath(import.meta.resolve("@fenglimg/fabric-server"));
59
+ }
60
+ function writeStderr(message) {
61
+ process.stderr.write(`${message}
62
+ `);
63
+ }
64
+ var configCmd = defineCommand({
65
+ meta: {
66
+ name: "config",
67
+ description: "Manage Fabric MCP client configuration."
68
+ },
69
+ subCommands: {
70
+ install: defineCommand({
71
+ meta: {
72
+ name: "install",
73
+ description: "Install Fabric MCP server entries into detected client configs."
74
+ },
75
+ args: {
76
+ clients: {
77
+ type: "string",
78
+ description: "Optional comma-separated client filter, e.g. cursor,codex,gemini."
79
+ },
80
+ "dry-run": {
81
+ type: "boolean",
82
+ description: "Print detected writes without changing files.",
83
+ default: false
84
+ }
85
+ },
86
+ async run({ args }) {
87
+ const workspaceRoot = process.cwd();
88
+ const fabricConfig = await loadFabricConfig(workspaceRoot);
89
+ const selectedClients = parseClientFilter(args.clients);
90
+ const serverPath = resolveServerPath();
91
+ const writers = resolveClients(workspaceRoot, fabricConfig).filter(
92
+ (writer) => selectedClients === null ? true : selectedClients.has(writer.clientKind)
93
+ );
94
+ if (writers.length === 0) {
95
+ writeStderr("No Fabric MCP client configs detected. Create a client directory or set fabric.config.json clientPaths.");
96
+ return;
97
+ }
98
+ for (const writer of writers) {
99
+ const configPath = await writer.detect(workspaceRoot);
100
+ if (configPath === null) {
101
+ writeStderr(`Skipping ${writer.clientKind}: no config path detected.`);
102
+ continue;
103
+ }
104
+ if (args["dry-run"]) {
105
+ writeStderr(`[dry-run] ${writer.clientKind}: would write ${configPath}`);
106
+ continue;
107
+ }
108
+ await writer.write(serverPath, workspaceRoot);
109
+ writeStderr(`${writer.clientKind}: wrote ${configPath}`);
110
+ }
111
+ }
112
+ })
113
+ }
114
+ });
115
+ var config_default = configCmd;
116
+ export {
117
+ configCmd,
118
+ config_default as default
119
+ };
@@ -0,0 +1,97 @@
1
+ // src/commands/hooks.ts
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
3
+ import { dirname, isAbsolute, join, parse, resolve } from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { defineCommand } from "citty";
6
+ var hooksCommand = defineCommand({
7
+ meta: {
8
+ name: "hooks",
9
+ description: "Manage Fabric git hook templates."
10
+ },
11
+ subCommands: {
12
+ install: defineCommand({
13
+ meta: {
14
+ name: "install",
15
+ description: "Install the Fabric Husky pre-commit hook template."
16
+ },
17
+ args: {
18
+ target: {
19
+ type: "string",
20
+ description: "Target project path. Defaults to the current working directory.",
21
+ default: process.cwd()
22
+ }
23
+ },
24
+ async run({ args }) {
25
+ const target = normalizeTarget(args.target);
26
+ assertExistingDirectory(target);
27
+ const huskyDir = join(target, ".husky");
28
+ const hookPath = join(huskyDir, "pre-commit");
29
+ const packageJsonPath = join(target, "package.json");
30
+ if (!existsSync(packageJsonPath)) {
31
+ throw new Error(`package.json is required to install hooks: ${packageJsonPath}`);
32
+ }
33
+ mkdirSync(huskyDir, { recursive: true });
34
+ writeFileSync(hookPath, readFileSync(findTemplatePath("templates/husky/pre-commit"), "utf8"), "utf8");
35
+ chmodSync(hookPath, 493);
36
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
37
+ const scripts = packageJson.scripts && typeof packageJson.scripts === "object" && !Array.isArray(packageJson.scripts) ? packageJson.scripts : {};
38
+ const hadPrepare = typeof scripts.prepare === "string" && scripts.prepare.trim().length > 0;
39
+ if (!hadPrepare) {
40
+ scripts.prepare = "husky install";
41
+ packageJson.scripts = scripts;
42
+ writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
43
+ `, "utf8");
44
+ }
45
+ writeStderr(`Installed ${hookPath}`);
46
+ if (hadPrepare) {
47
+ writeStderr(`Left existing prepare script unchanged in ${packageJsonPath}`);
48
+ } else {
49
+ writeStderr(`Added prepare script to ${packageJsonPath}`);
50
+ }
51
+ }
52
+ })
53
+ }
54
+ });
55
+ var hooks_default = hooksCommand;
56
+ function normalizeTarget(targetInput) {
57
+ return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
58
+ }
59
+ function assertExistingDirectory(target) {
60
+ if (!existsSync(target) || !statSync(target).isDirectory()) {
61
+ throw new Error(`Target must be an existing directory: ${target}`);
62
+ }
63
+ }
64
+ function findTemplatePath(relativePath) {
65
+ const currentModuleDir = dirname(fileURLToPath(import.meta.url));
66
+ const candidates = [
67
+ ...templateCandidatesFrom(process.cwd(), relativePath),
68
+ ...templateCandidatesFrom(currentModuleDir, relativePath)
69
+ ];
70
+ for (const candidate of candidates) {
71
+ if (existsSync(candidate)) {
72
+ return candidate;
73
+ }
74
+ }
75
+ throw new Error(`Template not found: ${relativePath}`);
76
+ }
77
+ function templateCandidatesFrom(start, relativePath) {
78
+ const candidates = [];
79
+ let current = resolve(start);
80
+ while (true) {
81
+ candidates.push(join(current, ...relativePath.split("/")));
82
+ const parent = dirname(current);
83
+ if (parent === current || parse(current).root === current) {
84
+ break;
85
+ }
86
+ current = parent;
87
+ }
88
+ return candidates;
89
+ }
90
+ function writeStderr(message) {
91
+ process.stderr.write(`${message}
92
+ `);
93
+ }
94
+ export {
95
+ hooks_default as default,
96
+ hooksCommand
97
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ humanLintCommand,
3
+ human_lint_default
4
+ } from "./chunk-KQ77ZBWO.js";
5
+ export {
6
+ human_lint_default as default,
7
+ humanLintCommand
8
+ };
@@ -0,0 +1,6 @@
1
+ import * as citty from 'citty';
2
+
3
+ declare const main: citty.CommandDef<citty.ArgsDef>;
4
+ declare function run(): Promise<void>;
5
+
6
+ export { main, run };
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // src/index.ts
2
+ import { resolve } from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { defineCommand, runMain } from "citty";
5
+
6
+ // src/commands/index.ts
7
+ var allCommands = {
8
+ bootstrap: () => import("./bootstrap-5JAUC3JW.js").then((module) => module.default),
9
+ init: () => import("./init-OM7PLR3J.js").then((module) => module.default),
10
+ scan: () => import("./scan-SE25KUZV.js").then((module) => module.default),
11
+ "sync-meta": () => import("./sync-meta-WM3A7FJP.js").then((module) => module.default),
12
+ "human-lint": () => import("./human-lint-P7SLDBZK.js").then((module) => module.default),
13
+ "ledger-append": () => import("./ledger-append-WA6ZJSMS.js").then((module) => module.default),
14
+ hooks: () => import("./hooks-2FGWPKQ3.js").then((module) => module.default),
15
+ config: () => import("./config-FC7AKEU7.js").then((module) => module.configCmd),
16
+ "pre-commit": () => import("./pre-commit-XKYQGUMV.js").then((module) => module.default)
17
+ };
18
+
19
+ // src/index.ts
20
+ var main = defineCommand({
21
+ meta: {
22
+ name: "fab",
23
+ version: "0.0.0",
24
+ description: "Fabric CLI"
25
+ },
26
+ subCommands: allCommands
27
+ });
28
+ async function run() {
29
+ await runMain(main);
30
+ }
31
+ var entrypoint = process.argv[1];
32
+ var currentFilePath = fileURLToPath(import.meta.url);
33
+ var isMainModule = entrypoint !== void 0 && resolve(entrypoint) === currentFilePath;
34
+ if (isMainModule) {
35
+ void run();
36
+ }
37
+ export {
38
+ main,
39
+ run
40
+ };
@@ -0,0 +1,148 @@
1
+ import {
2
+ createScanReport
3
+ } from "./chunk-RRDTXAUS.js";
4
+ import {
5
+ createDebugLogger,
6
+ resolveDevMode
7
+ } from "./chunk-JLIIQ75E.js";
8
+ import "./chunk-ZTNSMODH.js";
9
+
10
+ // src/commands/init.ts
11
+ import { createHash } from "crypto";
12
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
13
+ import { dirname, isAbsolute, join, parse, resolve } from "path";
14
+ import { fileURLToPath } from "url";
15
+ import { defineCommand } from "citty";
16
+ var initCommand = defineCommand({
17
+ meta: {
18
+ name: "init",
19
+ description: "Initialize Fabric in a target project."
20
+ },
21
+ args: {
22
+ target: {
23
+ type: "string",
24
+ description: "Target project path. Defaults to CLI target, EXTERNAL_FIXTURE_PATH, fabric.config.json, or cwd."
25
+ },
26
+ debug: {
27
+ type: "boolean",
28
+ description: "Print target resolution details to stderr.",
29
+ default: false
30
+ }
31
+ },
32
+ async run({ args }) {
33
+ const logger = createDebugLogger(args.debug);
34
+ const resolution = resolveDevMode(args.target, process.cwd());
35
+ const target = normalizeTarget(resolution.target);
36
+ logger(`init target source: ${resolution.source}`);
37
+ for (const step of resolution.chain) {
38
+ logger(step);
39
+ }
40
+ const created = initFabric(target);
41
+ console.log(`Created ${created.agentsPath}`);
42
+ console.log(`Created ${created.metaPath}`);
43
+ console.log(`Created ${created.humanLockPath}`);
44
+ console.log("Next: run fab hooks install to add the Day 4 pre-commit pipeline.");
45
+ }
46
+ });
47
+ var init_default = initCommand;
48
+ function initFabric(target) {
49
+ assertExistingDirectory(target);
50
+ const agentsPath = join(target, "AGENTS.md");
51
+ const fabricDir = join(target, ".fabric");
52
+ if (existsSync(agentsPath)) {
53
+ throw new Error(`ABORT: ${agentsPath} already exists. fab init is non-destructive.`);
54
+ }
55
+ if (existsSync(fabricDir)) {
56
+ throw new Error(`ABORT: ${fabricDir} already exists. fab init is non-destructive.`);
57
+ }
58
+ const scanReport = createScanReport(target);
59
+ const template = readFileSync(findTemplatePath("templates/agents-md/AGENTS.md.template"), "utf8");
60
+ const humanLockTemplate = readFileSync(findTemplatePath("templates/fabric/human-lock.json"), "utf8");
61
+ const packageName = readPackageName(target) ?? "// TODO: project name";
62
+ const agentsContent = template.replaceAll("{ projectName }", packageName).replaceAll("{ frameworkKind }", scanReport.framework.kind);
63
+ const agentsHash = sha256(agentsContent);
64
+ const meta = createInitialMeta(agentsHash);
65
+ const metaPath = join(fabricDir, "agents.meta.json");
66
+ const humanLockPath = join(fabricDir, "human-lock.json");
67
+ mkdirSync(fabricDir, { recursive: false });
68
+ writeNewFile(agentsPath, agentsContent);
69
+ writeNewFile(metaPath, `${JSON.stringify(meta, null, 2)}
70
+ `);
71
+ writeNewFile(humanLockPath, humanLockTemplate.endsWith("\n") ? humanLockTemplate : `${humanLockTemplate}
72
+ `);
73
+ return { agentsPath, metaPath, humanLockPath };
74
+ }
75
+ function normalizeTarget(targetInput) {
76
+ return isAbsolute(targetInput) ? targetInput : resolve(process.cwd(), targetInput);
77
+ }
78
+ function assertExistingDirectory(target) {
79
+ if (!existsSync(target) || !statSync(target).isDirectory()) {
80
+ throw new Error(`Target must be an existing directory: ${target}`);
81
+ }
82
+ }
83
+ function createInitialMeta(agentsHash) {
84
+ return {
85
+ revision: sha256(agentsHash),
86
+ nodes: {
87
+ L0: {
88
+ file: "AGENTS.md",
89
+ scope_glob: "**",
90
+ deps: [],
91
+ priority: "high",
92
+ hash: agentsHash
93
+ }
94
+ }
95
+ };
96
+ }
97
+ function readPackageName(target) {
98
+ const packageJsonPath = join(target, "package.json");
99
+ if (!existsSync(packageJsonPath)) {
100
+ return void 0;
101
+ }
102
+ try {
103
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
104
+ return packageJson.name;
105
+ } catch {
106
+ return void 0;
107
+ }
108
+ }
109
+ function findTemplatePath(relativePath) {
110
+ const currentModuleDir = dirname(fileURLToPath(import.meta.url));
111
+ const candidates = [
112
+ ...templateCandidatesFrom(process.cwd(), relativePath),
113
+ ...templateCandidatesFrom(currentModuleDir, relativePath)
114
+ ];
115
+ for (const candidate of candidates) {
116
+ if (existsSync(candidate)) {
117
+ return candidate;
118
+ }
119
+ }
120
+ throw new Error(`Template not found: ${relativePath}`);
121
+ }
122
+ function templateCandidatesFrom(start, relativePath) {
123
+ const candidates = [];
124
+ let current = resolve(start);
125
+ while (true) {
126
+ candidates.push(join(current, ...relativePath.split("/")));
127
+ const parent = dirname(current);
128
+ if (parent === current || parse(current).root === current) {
129
+ break;
130
+ }
131
+ current = parent;
132
+ }
133
+ return candidates;
134
+ }
135
+ function writeNewFile(path, content) {
136
+ if (existsSync(path)) {
137
+ throw new Error(`ABORT: ${path} already exists. fab init is non-destructive.`);
138
+ }
139
+ writeFileSync(path, content, "utf8");
140
+ }
141
+ function sha256(content) {
142
+ return `sha256:${createHash("sha256").update(content).digest("hex")}`;
143
+ }
144
+ export {
145
+ init_default as default,
146
+ initCommand,
147
+ initFabric
148
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ ledgerAppendCommand,
3
+ ledger_append_default
4
+ } from "./chunk-24U57BQE.js";
5
+ export {
6
+ ledger_append_default as default,
7
+ ledgerAppendCommand
8
+ };