-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.ts
More file actions
112 lines (101 loc) · 3.38 KB
/
Copy pathcli.ts
File metadata and controls
112 lines (101 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
import { Command } from "commander";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const program = new Command();
program
.name("pathfinder")
.description("The knowledge server for AI agents")
.version("1.16.0");
program
.command("init")
.description(
"Scaffold a new Pathfinder project (use --from <url> to auto-generate from a docs site)",
)
.option(
"--from <url>",
"Auto-generate config by crawling a documentation URL",
)
.option(
"--rate-limit <ms>",
"Milliseconds between requests (default: 500)",
parseInt,
)
.option("--max-pages <n>", "Maximum pages to crawl (default: 500)", parseInt)
.option("--force", "Overwrite existing pathfinder.yaml")
.action(async (opts) => {
const cwd = process.cwd();
if (opts.from) {
// Auto-generate from URL
const { initFromUrl } = await import("./cli-init.js");
await initFromUrl({
url: opts.from,
targetDir: cwd,
rateLimit: opts.rateLimit,
maxPages: opts.maxPages,
force: opts.force,
});
return;
}
// Original scaffold behavior
const yamlDest = path.join(cwd, "pathfinder.yaml");
if (fs.existsSync(yamlDest)) {
console.log("pathfinder.yaml already exists, skipping.");
} else {
const templatePath = path.join(
__dirname,
"..",
"pathfinder.example.yaml",
);
if (!fs.existsSync(templatePath)) {
console.error("Could not find pathfinder.example.yaml template.");
process.exit(1);
}
fs.copyFileSync(templatePath, yamlDest);
console.log("Created pathfinder.yaml");
}
const envDest = path.join(cwd, ".env");
if (fs.existsSync(envDest)) {
console.log(".env already exists, skipping.");
} else {
const envTemplatePath = path.join(__dirname, "..", ".env.example");
if (fs.existsSync(envTemplatePath)) {
fs.copyFileSync(envTemplatePath, envDest);
console.log("Created .env from template");
} else {
console.log("No .env.example found, skipping .env creation.");
}
}
console.log("\nEdit pathfinder.yaml to configure your docs sources.");
console.log("Then run: pathfinder serve");
});
program
.command("serve")
.description("Start the Pathfinder MCP server")
.option("-p, --port <port>", "Port to listen on", parseInt)
.option("-c, --config <path>", "Path to pathfinder.yaml")
.action(async (opts) => {
const { startServer } = await import("./server.js");
await startServer({
port: opts.port,
configPath: opts.config,
});
});
program
.command("validate")
.description("Validate config and probe source connectivity")
.option("-c, --config <path>", "Path to pathfinder.yaml")
.action(async (opts) => {
const { validateConfig, formatValidationResult } =
await import("./validate.js");
const result = await validateConfig(opts.config);
console.log(formatValidationResult(result));
// #88 — only hard `errors[]` fail the command. Optional-dependency
// advisories live in `result.warnings[]` and exit 0 (validate is a static
// linter; the eager `serve` startup guard is the real enforcement for a
// missing local-embedding peer).
process.exit(result.errors.length > 0 ? 1 : 0);
});
program.parse();