@usevyre/ai-context 0.2.0 → 0.2.2

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,91 @@
1
+ #!/usr/bin/env node
2
+ // npx @usevyre/ai-context init --claude|--cursor|--windsurf|--copilot
3
+
4
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
5
+ import { resolve, dirname } from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const distDir = resolve(__dirname, "../dist");
10
+
11
+ const TARGETS = {
12
+ "--claude": { src: "claude-context.md", dest: "CLAUDE.md", label: "CLAUDE.md" },
13
+ "--cursor": { src: "cursor-rules.md", dest: ".cursor/rules", label: ".cursor/rules" },
14
+ "--windsurf": { src: "windsurf-rules.md", dest: ".windsurf/rules", label: ".windsurf/rules" },
15
+ "--copilot": { src: "copilot-instructions.md", dest: ".github/copilot-instructions.md", label: ".github/copilot-instructions.md" },
16
+ };
17
+
18
+ const MARKER_START = "<!-- usevyre-context:start -->";
19
+ const MARKER_END = "<!-- usevyre-context:end -->";
20
+
21
+ function run() {
22
+ const args = process.argv.slice(2);
23
+ const flag = args.find((a) => a.startsWith("--"));
24
+
25
+ if (!flag || flag === "--help") {
26
+ console.log(`
27
+ Usage: npx @usevyre/ai-context init <flag>
28
+
29
+ Flags:
30
+ --claude Write context to CLAUDE.md
31
+ --cursor Write context to .cursor/rules
32
+ --windsurf Write context to .windsurf/rules
33
+ --copilot Write context to .github/copilot-instructions.md
34
+ `);
35
+ process.exit(flag === "--help" ? 0 : 1);
36
+ }
37
+
38
+ const target = TARGETS[flag];
39
+ if (!target) {
40
+ console.error(`Unknown flag: ${flag}`);
41
+ console.error(`Valid flags: ${Object.keys(TARGETS).join(", ")}`);
42
+ process.exit(1);
43
+ }
44
+
45
+ const srcPath = resolve(distDir, target.src);
46
+ const destPath = resolve(process.cwd(), target.dest);
47
+
48
+ if (!existsSync(srcPath)) {
49
+ console.error(`Source file not found: ${srcPath}`);
50
+ console.error("Run 'pnpm build' in packages/ai-context first.");
51
+ process.exit(1);
52
+ }
53
+
54
+ const content = readFileSync(srcPath, "utf-8");
55
+ const block = `${MARKER_START}\n${content.trim()}\n${MARKER_END}`;
56
+
57
+ // Ensure destination directory exists
58
+ const destDir = dirname(destPath);
59
+ if (!existsSync(destDir)) mkdirSync(destDir, { recursive: true });
60
+
61
+ if (existsSync(destPath)) {
62
+ let existing = readFileSync(destPath, "utf-8");
63
+
64
+ if (existing.includes(MARKER_START)) {
65
+ // Replace existing block between markers
66
+ const re = new RegExp(
67
+ `${escapeRe(MARKER_START)}[\\s\\S]*?${escapeRe(MARKER_END)}`,
68
+ "m"
69
+ );
70
+ existing = existing.replace(re, block);
71
+ writeFileSync(destPath, existing, "utf-8");
72
+ console.log(`✓ Updated useVyre context block in ${target.label}`);
73
+ } else {
74
+ // Append to existing file
75
+ writeFileSync(destPath, existing.trimEnd() + "\n\n" + block + "\n", "utf-8");
76
+ console.log(`✓ Appended useVyre context block to ${target.label}`);
77
+ }
78
+ } else {
79
+ // Create new file
80
+ writeFileSync(destPath, block + "\n", "utf-8");
81
+ console.log(`✓ Created ${target.label} with useVyre context`);
82
+ }
83
+
84
+ console.log(` Re-run this command after upgrading @usevyre packages.`);
85
+ }
86
+
87
+ function escapeRe(str) {
88
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
89
+ }
90
+
91
+ run();