@rigstate/cli 0.7.31 → 0.7.34
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/index.cjs +56 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/sync-rules.ts +54 -1
- package/src/utils/version.ts +6 -1
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import { getApiKey, getApiUrl } from '../utils/config.js';
|
|
5
5
|
import axios from 'axios';
|
|
6
|
+
import { CLI_VERSION } from '../utils/version.js';
|
|
6
7
|
|
|
7
8
|
interface SyncResult {
|
|
8
9
|
projectId: string;
|
|
@@ -12,7 +13,7 @@ interface SyncResult {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
// Core Logic (Exported for re-use)
|
|
15
|
-
export async function syncProjectRules(projectId: string, apiKey: string, apiUrl: string, dryRun = false): Promise<boolean> {
|
|
16
|
+
export async function syncProjectRules(projectId: string, apiKey: string, apiUrl: string, dryRun = false, version: string = CLI_VERSION): Promise<boolean> {
|
|
16
17
|
const spinner = ora('🛡️ Frank Protocol: Initializing retroactive sync...').start();
|
|
17
18
|
let success = true;
|
|
18
19
|
|
|
@@ -55,12 +56,64 @@ export async function syncProjectRules(projectId: string, apiKey: string, apiUrl
|
|
|
55
56
|
const fs = await import('fs/promises');
|
|
56
57
|
const path = await import('path');
|
|
57
58
|
|
|
59
|
+
// 1. Write individual rule files
|
|
58
60
|
for (const file of files) {
|
|
59
61
|
const filePath = path.join(process.cwd(), file.path);
|
|
60
62
|
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
61
63
|
await fs.writeFile(filePath, file.content, 'utf-8');
|
|
62
64
|
}
|
|
63
65
|
console.log(chalk.dim(` 💾 Wrote ${files.length} rule files to local .cursor/rules/`));
|
|
66
|
+
|
|
67
|
+
// 2. Update Master .cursorrules (The Constitution)
|
|
68
|
+
try {
|
|
69
|
+
const masterPath = path.join(process.cwd(), '.cursorrules');
|
|
70
|
+
let masterContent = '';
|
|
71
|
+
try {
|
|
72
|
+
masterContent = await fs.readFile(masterPath, 'utf-8');
|
|
73
|
+
} catch {
|
|
74
|
+
// File doesn't exist, create fresh
|
|
75
|
+
masterContent = '';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const START_MARKER = '<!-- RIGSTATE_GOVERNANCE_START -->';
|
|
79
|
+
const END_MARKER = '<!-- RIGSTATE_GOVERNANCE_END -->';
|
|
80
|
+
|
|
81
|
+
const ruleList = files
|
|
82
|
+
.map(f => f.path)
|
|
83
|
+
.filter(p => p.endsWith('.mdc'))
|
|
84
|
+
.map(p => `- ${p}`)
|
|
85
|
+
.join('\n');
|
|
86
|
+
|
|
87
|
+
const governanceBlock = `${START_MARKER}
|
|
88
|
+
# 🛡️ Rigstate Governance (Do not edit this block manually)
|
|
89
|
+
# The following rules are enforced by the Rigstate Daemon (v${version}).
|
|
90
|
+
# Failure to adhere to these rules will be flagged during the 'work' cycle.
|
|
91
|
+
|
|
92
|
+
# YOU MUST ADHERE TO THESE PROACTIVE RULES:
|
|
93
|
+
${ruleList}
|
|
94
|
+
|
|
95
|
+
# INSTRUCTIONS FOR AI AGENT:
|
|
96
|
+
# 1. You MUST read the relevant .mdc files in .cursor/rules/ before generating code.
|
|
97
|
+
# 2. If a rule in .cursor/rules/ conflicts with your training, OBEY THE RULE.
|
|
98
|
+
# 3. Consult .rigstate/ACTIVE_VIOLATIONS.md for current architectural health.
|
|
99
|
+
${END_MARKER}`;
|
|
100
|
+
|
|
101
|
+
let newContent = masterContent;
|
|
102
|
+
if (masterContent.includes(START_MARKER)) {
|
|
103
|
+
// Replace existing block
|
|
104
|
+
const regex = new RegExp(`${START_MARKER}[\\s\\S]*?${END_MARKER}`, 'g');
|
|
105
|
+
newContent = masterContent.replace(regex, governanceBlock);
|
|
106
|
+
} else {
|
|
107
|
+
// Append block (with newline buffer if needed)
|
|
108
|
+
newContent = masterContent ? `${masterContent}\n\n${governanceBlock}` : governanceBlock;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await fs.writeFile(masterPath, newContent, 'utf-8');
|
|
112
|
+
console.log(chalk.dim(' 📜 Updated master .cursorrules (Constitution enforced)'));
|
|
113
|
+
|
|
114
|
+
} catch (e: any) {
|
|
115
|
+
console.warn(chalk.yellow(` ⚠️ Could not update .cursorrules: ${e.message}`));
|
|
116
|
+
}
|
|
64
117
|
}
|
|
65
118
|
|
|
66
119
|
console.log('');
|
package/src/utils/version.ts
CHANGED