reffy-cli 0.6.1 → 0.6.4
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/cli.js +32 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { promises as fs } from "node:fs";
|
|
2
|
+
import { existsSync, promises as fs, statSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { renderDiagram } from "./diagram.js";
|
|
5
5
|
import { runDoctor } from "./doctor.js";
|
|
@@ -139,6 +139,36 @@ async function initAgents(repoRoot) {
|
|
|
139
139
|
await fs.writeFile(reffyAgentsPath, REFFY_AGENTS_CONTENT, "utf8");
|
|
140
140
|
return { root_agents_path: agentsPath, reffy_agents_path: reffyAgentsPath };
|
|
141
141
|
}
|
|
142
|
+
function pathExists(targetPath) {
|
|
143
|
+
return existsSync(targetPath);
|
|
144
|
+
}
|
|
145
|
+
function isDirectory(targetPath) {
|
|
146
|
+
try {
|
|
147
|
+
return statSync(targetPath).isDirectory();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function discoverRepoRoot(startDir) {
|
|
154
|
+
let current = path.resolve(startDir);
|
|
155
|
+
while (true) {
|
|
156
|
+
if (path.basename(current) === ".references" && isDirectory(path.join(current, "artifacts"))) {
|
|
157
|
+
return path.dirname(current);
|
|
158
|
+
}
|
|
159
|
+
if (isDirectory(path.join(current, ".references"))) {
|
|
160
|
+
return current;
|
|
161
|
+
}
|
|
162
|
+
if (pathExists(path.join(current, "AGENTS.md")) || pathExists(path.join(current, ".git"))) {
|
|
163
|
+
return current;
|
|
164
|
+
}
|
|
165
|
+
const parent = path.dirname(current);
|
|
166
|
+
if (parent === current) {
|
|
167
|
+
return path.resolve(startDir);
|
|
168
|
+
}
|
|
169
|
+
current = parent;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
142
172
|
function parseRepoArg(argv) {
|
|
143
173
|
for (let i = 0; i < argv.length; i += 1) {
|
|
144
174
|
const arg = argv[i];
|
|
@@ -155,7 +185,7 @@ function parseRepoArg(argv) {
|
|
|
155
185
|
return path.resolve(value);
|
|
156
186
|
}
|
|
157
187
|
}
|
|
158
|
-
return process.cwd();
|
|
188
|
+
return discoverRepoRoot(process.cwd());
|
|
159
189
|
}
|
|
160
190
|
function parseOutputMode(argv) {
|
|
161
191
|
for (let i = 0; i < argv.length; i += 1) {
|