@rigstate/cli 0.7.22 → 0.7.23
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 +432 -432
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +429 -429
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/link.ts +7 -6
- package/src/commands/mcp.ts +20 -5
- package/.rigstate/daemon.pid +0 -1
package/dist/index.cjs
CHANGED
|
@@ -382,136 +382,6 @@ var init_suggest = __esm({
|
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
-
// src/commands/hooks.ts
|
|
386
|
-
var hooks_exports = {};
|
|
387
|
-
__export(hooks_exports, {
|
|
388
|
-
createHooksCommand: () => createHooksCommand
|
|
389
|
-
});
|
|
390
|
-
function createHooksCommand() {
|
|
391
|
-
const hooks = new import_commander4.Command("hooks").description("Manage git hooks for Guardian integration");
|
|
392
|
-
hooks.command("install").description("Install pre-commit hook to run Guardian checks").option("--strict [level]", 'Strict level: "all" or "critical" (default)', "critical").action(async (options) => {
|
|
393
|
-
try {
|
|
394
|
-
const gitDir = import_path2.default.join(process.cwd(), ".git");
|
|
395
|
-
try {
|
|
396
|
-
await import_promises2.default.access(gitDir);
|
|
397
|
-
} catch {
|
|
398
|
-
console.log(import_chalk5.default.red("\u274C Not a git repository."));
|
|
399
|
-
console.log(import_chalk5.default.dim(' Initialize with "git init" first.'));
|
|
400
|
-
process.exit(1);
|
|
401
|
-
}
|
|
402
|
-
const hooksDir = import_path2.default.join(gitDir, "hooks");
|
|
403
|
-
await import_promises2.default.mkdir(hooksDir, { recursive: true });
|
|
404
|
-
const preCommitPath = import_path2.default.join(hooksDir, "pre-commit");
|
|
405
|
-
let existingContent = "";
|
|
406
|
-
try {
|
|
407
|
-
existingContent = await import_promises2.default.readFile(preCommitPath, "utf-8");
|
|
408
|
-
if (existingContent.includes("rigstate")) {
|
|
409
|
-
console.log(import_chalk5.default.yellow("\u26A0 Rigstate pre-commit hook already installed."));
|
|
410
|
-
console.log(import_chalk5.default.dim(' Use "rigstate hooks uninstall" to remove first.'));
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
} catch {
|
|
414
|
-
}
|
|
415
|
-
let script = PRE_COMMIT_SCRIPT;
|
|
416
|
-
if (options.strict === "all") {
|
|
417
|
-
script = script.replace("--strict=critical", "--strict");
|
|
418
|
-
}
|
|
419
|
-
if (existingContent && !existingContent.includes("rigstate")) {
|
|
420
|
-
const combinedScript = existingContent + "\n\n" + script.replace("#!/bin/sh\n", "");
|
|
421
|
-
await import_promises2.default.writeFile(preCommitPath, combinedScript, { mode: 493 });
|
|
422
|
-
console.log(import_chalk5.default.green("\u2705 Rigstate hook appended to existing pre-commit."));
|
|
423
|
-
} else {
|
|
424
|
-
await import_promises2.default.writeFile(preCommitPath, script, { mode: 493 });
|
|
425
|
-
console.log(import_chalk5.default.green("\u2705 Pre-commit hook installed!"));
|
|
426
|
-
}
|
|
427
|
-
console.log(import_chalk5.default.dim(` Path: ${preCommitPath}`));
|
|
428
|
-
console.log(import_chalk5.default.dim(` Strict level: ${options.strict}`));
|
|
429
|
-
console.log("");
|
|
430
|
-
console.log(import_chalk5.default.cyan("Guardian will now check your code before each commit."));
|
|
431
|
-
console.log(import_chalk5.default.dim('Use "rigstate hooks uninstall" to remove the hook.'));
|
|
432
|
-
} catch (error) {
|
|
433
|
-
console.error(import_chalk5.default.red("Failed to install hook:"), error.message);
|
|
434
|
-
process.exit(1);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
hooks.command("uninstall").description("Remove Rigstate pre-commit hook").action(async () => {
|
|
438
|
-
try {
|
|
439
|
-
const preCommitPath = import_path2.default.join(process.cwd(), ".git", "hooks", "pre-commit");
|
|
440
|
-
try {
|
|
441
|
-
const content = await import_promises2.default.readFile(preCommitPath, "utf-8");
|
|
442
|
-
if (!content.includes("rigstate")) {
|
|
443
|
-
console.log(import_chalk5.default.yellow("\u26A0 No Rigstate hook found in pre-commit."));
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
if (content.includes("# Rigstate Guardian Pre-commit Hook") && content.trim().split("\n").filter((l) => l && !l.startsWith("#")).length <= 4) {
|
|
447
|
-
await import_promises2.default.unlink(preCommitPath);
|
|
448
|
-
console.log(import_chalk5.default.green("\u2705 Pre-commit hook removed."));
|
|
449
|
-
} else {
|
|
450
|
-
const lines = content.split("\n");
|
|
451
|
-
const filteredLines = [];
|
|
452
|
-
let inRigstateSection = false;
|
|
453
|
-
for (const line of lines) {
|
|
454
|
-
if (line.includes("Rigstate Guardian Pre-commit Hook")) {
|
|
455
|
-
inRigstateSection = true;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
if (inRigstateSection && line.includes("exit $?")) {
|
|
459
|
-
inRigstateSection = false;
|
|
460
|
-
continue;
|
|
461
|
-
}
|
|
462
|
-
if (!inRigstateSection && !line.includes("rigstate check")) {
|
|
463
|
-
filteredLines.push(line);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
await import_promises2.default.writeFile(preCommitPath, filteredLines.join("\n"), { mode: 493 });
|
|
467
|
-
console.log(import_chalk5.default.green("\u2705 Rigstate section removed from pre-commit hook."));
|
|
468
|
-
}
|
|
469
|
-
} catch {
|
|
470
|
-
console.log(import_chalk5.default.yellow("\u26A0 No pre-commit hook found."));
|
|
471
|
-
}
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error(import_chalk5.default.red("Failed to uninstall hook:"), error.message);
|
|
474
|
-
process.exit(1);
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
return hooks;
|
|
478
|
-
}
|
|
479
|
-
var import_commander4, import_chalk5, import_promises2, import_path2, PRE_COMMIT_SCRIPT;
|
|
480
|
-
var init_hooks = __esm({
|
|
481
|
-
"src/commands/hooks.ts"() {
|
|
482
|
-
"use strict";
|
|
483
|
-
init_cjs_shims();
|
|
484
|
-
import_commander4 = require("commander");
|
|
485
|
-
import_chalk5 = __toESM(require("chalk"), 1);
|
|
486
|
-
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
487
|
-
import_path2 = __toESM(require("path"), 1);
|
|
488
|
-
PRE_COMMIT_SCRIPT = `#!/bin/sh
|
|
489
|
-
# Rigstate Guardian Pre-commit Hook
|
|
490
|
-
# Installed by: rigstate hooks install
|
|
491
|
-
|
|
492
|
-
# 1. Silent Sentinel Check (Phase 5)
|
|
493
|
-
if [ -f .rigstate/guardian.lock ]; then
|
|
494
|
-
echo "\u{1F6D1} INTERVENTION ACTIVE: Commit blocked by Silent Sentinel."
|
|
495
|
-
echo " A critical violation ('HARD_LOCK') was detected by the Guardian Daemon."
|
|
496
|
-
echo " Please fix the violation to unlock the repo."
|
|
497
|
-
echo ""
|
|
498
|
-
if grep -q "HARD_LOCK_ACTIVE" .rigstate/guardian.lock; then
|
|
499
|
-
cat .rigstate/guardian.lock
|
|
500
|
-
fi
|
|
501
|
-
exit 1
|
|
502
|
-
fi
|
|
503
|
-
|
|
504
|
-
echo "\u{1F6E1}\uFE0F Running Guardian checks..."
|
|
505
|
-
|
|
506
|
-
# Run check with strict mode for critical violations
|
|
507
|
-
rigstate check --staged --strict=critical
|
|
508
|
-
|
|
509
|
-
# Exit with the same code as rigstate check
|
|
510
|
-
exit $?
|
|
511
|
-
`;
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
|
|
515
385
|
// src/utils/skills-provisioner.ts
|
|
516
386
|
var skills_provisioner_exports = {};
|
|
517
387
|
__export(skills_provisioner_exports, {
|
|
@@ -540,18 +410,18 @@ async function provisionSkills(apiUrl, apiKey, projectId, rootDir) {
|
|
|
540
410
|
}
|
|
541
411
|
} catch (e) {
|
|
542
412
|
const msg = e.response?.data?.error || e.message;
|
|
543
|
-
console.log(
|
|
413
|
+
console.log(import_chalk8.default.dim(` (Skills API not available: ${msg}, using core library)`));
|
|
544
414
|
}
|
|
545
415
|
if (skills.length === 0) {
|
|
546
416
|
const { getRigstateStandardSkills } = await import("@rigstate/rules-engine");
|
|
547
417
|
const coreSkills = getRigstateStandardSkills();
|
|
548
418
|
skills.push(...coreSkills);
|
|
549
419
|
}
|
|
550
|
-
const skillsDir =
|
|
551
|
-
await
|
|
420
|
+
const skillsDir = import_path6.default.join(rootDir, ".agent", "skills");
|
|
421
|
+
await import_promises6.default.mkdir(skillsDir, { recursive: true });
|
|
552
422
|
for (const skill of skills) {
|
|
553
|
-
const skillDir =
|
|
554
|
-
await
|
|
423
|
+
const skillDir = import_path6.default.join(skillsDir, skill.name);
|
|
424
|
+
await import_promises6.default.mkdir(skillDir, { recursive: true });
|
|
555
425
|
const skillContent = `---
|
|
556
426
|
name: ${skill.name}
|
|
557
427
|
description: ${skill.description}
|
|
@@ -564,10 +434,10 @@ ${skill.content}
|
|
|
564
434
|
|
|
565
435
|
---
|
|
566
436
|
*Provisioned by Rigstate CLI. Do not modify manually.*`;
|
|
567
|
-
const skillPath =
|
|
568
|
-
await
|
|
437
|
+
const skillPath = import_path6.default.join(skillDir, "SKILL.md");
|
|
438
|
+
await import_promises6.default.writeFile(skillPath, skillContent, "utf-8");
|
|
569
439
|
}
|
|
570
|
-
console.log(
|
|
440
|
+
console.log(import_chalk8.default.green(` \u2705 Provisioned ${skills.length} skill(s) to .agent/skills/`));
|
|
571
441
|
return skills;
|
|
572
442
|
}
|
|
573
443
|
function generateSkillsDiscoveryBlock(skills) {
|
|
@@ -582,16 +452,16 @@ ${skillBlocks}
|
|
|
582
452
|
</available_skills>`;
|
|
583
453
|
}
|
|
584
454
|
async function jitProvisionSkill(skillId, apiUrl, apiKey, projectId, rootDir) {
|
|
585
|
-
const rulesPath =
|
|
455
|
+
const rulesPath = import_path6.default.join(rootDir, ".cursorrules");
|
|
586
456
|
let rulesContent = "";
|
|
587
457
|
try {
|
|
588
|
-
rulesContent = await
|
|
458
|
+
rulesContent = await import_promises6.default.readFile(rulesPath, "utf-8");
|
|
589
459
|
} catch (e) {
|
|
590
460
|
return false;
|
|
591
461
|
}
|
|
592
462
|
const isProvisioned = rulesContent.includes(`<name>${skillId}</name>`) || rulesContent.includes(`.agent/skills/${skillId}`);
|
|
593
463
|
if (isProvisioned) return false;
|
|
594
|
-
console.log(
|
|
464
|
+
console.log(import_chalk8.default.yellow(` \u26A1 JIT PROVISIONING: Injecting ${skillId}...`));
|
|
595
465
|
try {
|
|
596
466
|
const skills = await provisionSkills(apiUrl, apiKey, projectId, rootDir);
|
|
597
467
|
const skillsBlock = generateSkillsDiscoveryBlock(skills);
|
|
@@ -606,22 +476,22 @@ async function jitProvisionSkill(skillId, apiUrl, apiKey, projectId, rootDir) {
|
|
|
606
476
|
rulesContent = rulesContent.slice(0, insertPoint + 3) + "\n\n" + skillsBlock + "\n" + rulesContent.slice(insertPoint + 3);
|
|
607
477
|
}
|
|
608
478
|
}
|
|
609
|
-
await
|
|
479
|
+
await import_promises6.default.writeFile(rulesPath, rulesContent, "utf-8");
|
|
610
480
|
return true;
|
|
611
481
|
} catch (e) {
|
|
612
|
-
console.log(
|
|
482
|
+
console.log(import_chalk8.default.red(` Failed to provision skill: ${e.message}`));
|
|
613
483
|
return false;
|
|
614
484
|
}
|
|
615
485
|
}
|
|
616
|
-
var import_axios6,
|
|
486
|
+
var import_axios6, import_promises6, import_path6, import_chalk8;
|
|
617
487
|
var init_skills_provisioner = __esm({
|
|
618
488
|
"src/utils/skills-provisioner.ts"() {
|
|
619
489
|
"use strict";
|
|
620
490
|
init_cjs_shims();
|
|
621
491
|
import_axios6 = __toESM(require("axios"), 1);
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
492
|
+
import_promises6 = __toESM(require("fs/promises"), 1);
|
|
493
|
+
import_path6 = __toESM(require("path"), 1);
|
|
494
|
+
import_chalk8 = __toESM(require("chalk"), 1);
|
|
625
495
|
}
|
|
626
496
|
});
|
|
627
497
|
|
|
@@ -637,8 +507,8 @@ __export(governance_exports, {
|
|
|
637
507
|
});
|
|
638
508
|
async function getGovernanceConfig(rootDir = process.cwd()) {
|
|
639
509
|
try {
|
|
640
|
-
const configPath =
|
|
641
|
-
const content = await
|
|
510
|
+
const configPath = import_path7.default.join(rootDir, "rigstate.config.json");
|
|
511
|
+
const content = await import_promises7.default.readFile(configPath, "utf-8");
|
|
642
512
|
const userConfig = JSON.parse(content);
|
|
643
513
|
return {
|
|
644
514
|
governance: {
|
|
@@ -652,50 +522,50 @@ async function getGovernanceConfig(rootDir = process.cwd()) {
|
|
|
652
522
|
}
|
|
653
523
|
async function getSessionState(rootDir = process.cwd()) {
|
|
654
524
|
try {
|
|
655
|
-
const sessionPath =
|
|
656
|
-
const content = await
|
|
525
|
+
const sessionPath = import_path7.default.join(rootDir, ".rigstate", "session.json");
|
|
526
|
+
const content = await import_promises7.default.readFile(sessionPath, "utf-8");
|
|
657
527
|
return JSON.parse(content);
|
|
658
528
|
} catch (e) {
|
|
659
529
|
return DEFAULT_SESSION;
|
|
660
530
|
}
|
|
661
531
|
}
|
|
662
532
|
async function setSoftLock(reason, violationId, rootDir = process.cwd()) {
|
|
663
|
-
const sessionPath =
|
|
533
|
+
const sessionPath = import_path7.default.join(rootDir, ".rigstate", "session.json");
|
|
664
534
|
const state = {
|
|
665
535
|
status: "SOFT_LOCK",
|
|
666
536
|
active_violation: violationId,
|
|
667
537
|
lock_reason: reason,
|
|
668
538
|
last_updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
669
539
|
};
|
|
670
|
-
await
|
|
671
|
-
await
|
|
540
|
+
await import_promises7.default.mkdir(import_path7.default.dirname(sessionPath), { recursive: true });
|
|
541
|
+
await import_promises7.default.writeFile(sessionPath, JSON.stringify(state, null, 2), "utf-8");
|
|
672
542
|
}
|
|
673
543
|
async function clearSoftLock(rootDir = process.cwd()) {
|
|
674
|
-
const sessionPath =
|
|
544
|
+
const sessionPath = import_path7.default.join(rootDir, ".rigstate", "session.json");
|
|
675
545
|
const state = {
|
|
676
546
|
...DEFAULT_SESSION,
|
|
677
547
|
last_updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
678
548
|
};
|
|
679
|
-
await
|
|
680
|
-
await
|
|
549
|
+
await import_promises7.default.mkdir(import_path7.default.dirname(sessionPath), { recursive: true });
|
|
550
|
+
await import_promises7.default.writeFile(sessionPath, JSON.stringify(state, null, 2), "utf-8");
|
|
681
551
|
}
|
|
682
552
|
async function performOverride(violationId, reason, rootDir = process.cwd()) {
|
|
683
553
|
const config2 = await getGovernanceConfig(rootDir);
|
|
684
554
|
if (!config2.governance.allow_overrides) {
|
|
685
|
-
console.log(
|
|
555
|
+
console.log(import_chalk9.default.red("\u274C Overrides are disabled for this project."));
|
|
686
556
|
return false;
|
|
687
557
|
}
|
|
688
558
|
await clearSoftLock(rootDir);
|
|
689
559
|
return true;
|
|
690
560
|
}
|
|
691
|
-
var
|
|
561
|
+
var import_promises7, import_path7, import_chalk9, InterventionLevel, DEFAULT_CONFIG, DEFAULT_SESSION;
|
|
692
562
|
var init_governance = __esm({
|
|
693
563
|
"src/utils/governance.ts"() {
|
|
694
564
|
"use strict";
|
|
695
565
|
init_cjs_shims();
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
566
|
+
import_promises7 = __toESM(require("fs/promises"), 1);
|
|
567
|
+
import_path7 = __toESM(require("path"), 1);
|
|
568
|
+
import_chalk9 = __toESM(require("chalk"), 1);
|
|
699
569
|
InterventionLevel = /* @__PURE__ */ ((InterventionLevel2) => {
|
|
700
570
|
InterventionLevel2[InterventionLevel2["GHOST"] = 0] = "GHOST";
|
|
701
571
|
InterventionLevel2[InterventionLevel2["NUDGE"] = 1] = "NUDGE";
|
|
@@ -724,16 +594,16 @@ __export(watchdog_exports, {
|
|
|
724
594
|
});
|
|
725
595
|
async function countLines(filePath) {
|
|
726
596
|
try {
|
|
727
|
-
const content = await
|
|
597
|
+
const content = await import_promises8.default.readFile(filePath, "utf-8");
|
|
728
598
|
return content.split("\n").length;
|
|
729
599
|
} catch (e) {
|
|
730
600
|
return 0;
|
|
731
601
|
}
|
|
732
602
|
}
|
|
733
603
|
async function getFiles(dir, extension) {
|
|
734
|
-
const entries = await
|
|
604
|
+
const entries = await import_promises8.default.readdir(dir, { withFileTypes: true });
|
|
735
605
|
const files = await Promise.all(entries.map(async (entry) => {
|
|
736
|
-
const res =
|
|
606
|
+
const res = import_path8.default.resolve(dir, entry.name);
|
|
737
607
|
if (entry.isDirectory()) {
|
|
738
608
|
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".next" || entry.name === "dist") return [];
|
|
739
609
|
return getFiles(res, extension);
|
|
@@ -761,8 +631,8 @@ async function fetchRulesFromApi(projectId) {
|
|
|
761
631
|
}
|
|
762
632
|
} catch (error) {
|
|
763
633
|
try {
|
|
764
|
-
const cachePath =
|
|
765
|
-
const content = await
|
|
634
|
+
const cachePath = import_path8.default.join(process.cwd(), CACHE_FILE);
|
|
635
|
+
const content = await import_promises8.default.readFile(cachePath, "utf-8");
|
|
766
636
|
const cached = JSON.parse(content);
|
|
767
637
|
if (cached.settings) {
|
|
768
638
|
return {
|
|
@@ -781,7 +651,7 @@ async function fetchRulesFromApi(projectId) {
|
|
|
781
651
|
};
|
|
782
652
|
}
|
|
783
653
|
async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
784
|
-
console.log(
|
|
654
|
+
console.log(import_chalk10.default.bold("\n\u{1F6E1}\uFE0F Active Guardian Watchdog Initiated..."));
|
|
785
655
|
let lmax = settings.lmax || DEFAULT_LMAX;
|
|
786
656
|
let lmaxWarning = settings.lmax_warning || DEFAULT_LMAX_WARNING;
|
|
787
657
|
let ruleSource = settings.lmax ? "Settings (Passed)" : "Default";
|
|
@@ -791,47 +661,47 @@ async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
|
791
661
|
lmaxWarning = apiRules.lmaxWarning;
|
|
792
662
|
ruleSource = apiRules.source;
|
|
793
663
|
}
|
|
794
|
-
console.log(
|
|
664
|
+
console.log(import_chalk10.default.dim(`Governance Rules: L_max=${lmax}, L_max_warning=${lmaxWarning}, Source: ${ruleSource}`));
|
|
795
665
|
const targetExtensions = [".ts", ".tsx"];
|
|
796
666
|
let scanTarget = rootPath;
|
|
797
|
-
const webSrc =
|
|
667
|
+
const webSrc = import_path8.default.join(rootPath, "apps", "web", "src");
|
|
798
668
|
try {
|
|
799
|
-
await
|
|
669
|
+
await import_promises8.default.access(webSrc);
|
|
800
670
|
scanTarget = webSrc;
|
|
801
671
|
} catch {
|
|
802
672
|
}
|
|
803
|
-
console.log(
|
|
673
|
+
console.log(import_chalk10.default.dim(`Scanning target: ${import_path8.default.relative(process.cwd(), scanTarget)}`));
|
|
804
674
|
const files = await getFiles(scanTarget, targetExtensions);
|
|
805
675
|
let violations = 0;
|
|
806
676
|
let warnings = 0;
|
|
807
677
|
const results = [];
|
|
808
678
|
for (const file of files) {
|
|
809
679
|
const lines = await countLines(file);
|
|
810
|
-
const relPath =
|
|
680
|
+
const relPath = import_path8.default.relative(rootPath, file);
|
|
811
681
|
if (lines > lmax) {
|
|
812
682
|
results.push({ file: relPath, lines, status: "VIOLATION" });
|
|
813
683
|
violations++;
|
|
814
|
-
console.log(
|
|
684
|
+
console.log(import_chalk10.default.red(`[VIOLATION] ${relPath}: ${lines} lines (Limit: ${lmax})`));
|
|
815
685
|
} else if (lines > lmaxWarning) {
|
|
816
686
|
results.push({ file: relPath, lines, status: "WARNING" });
|
|
817
687
|
warnings++;
|
|
818
|
-
console.log(
|
|
688
|
+
console.log(import_chalk10.default.yellow(`[WARNING] ${relPath}: ${lines} lines (Threshold: ${lmaxWarning})`));
|
|
819
689
|
}
|
|
820
690
|
}
|
|
821
691
|
if (violations === 0 && warnings === 0) {
|
|
822
|
-
console.log(
|
|
692
|
+
console.log(import_chalk10.default.green(`\u2714 All ${files.length} files are within governance limits.`));
|
|
823
693
|
} else {
|
|
824
|
-
console.log("\n" +
|
|
825
|
-
console.log(
|
|
826
|
-
console.log(
|
|
694
|
+
console.log("\n" + import_chalk10.default.bold("Summary:"));
|
|
695
|
+
console.log(import_chalk10.default.red(`Violations: ${violations}`));
|
|
696
|
+
console.log(import_chalk10.default.yellow(`Warnings: ${warnings}`));
|
|
827
697
|
const { getGovernanceConfig: getGovernanceConfig2, setSoftLock: setSoftLock2, InterventionLevel: InterventionLevel2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
|
|
828
698
|
const { governance } = await getGovernanceConfig2(rootPath);
|
|
829
|
-
console.log(
|
|
699
|
+
console.log(import_chalk10.default.dim(`Intervention Level: ${InterventionLevel2[governance.intervention_level] || "UNKNOWN"} (${governance.intervention_level})`));
|
|
830
700
|
if (violations > 0) {
|
|
831
|
-
console.log(
|
|
701
|
+
console.log(import_chalk10.default.red.bold("\nCRITICAL: Governance violations detected. Immediate refactoring required."));
|
|
832
702
|
if (governance.intervention_level >= InterventionLevel2.SENTINEL) {
|
|
833
|
-
console.log(
|
|
834
|
-
console.log(
|
|
703
|
+
console.log(import_chalk10.default.red.bold("\u{1F6D1} SENTINEL MODE: Session SOFT_LOCKED until resolved."));
|
|
704
|
+
console.log(import_chalk10.default.red(' Run "rigstate override <id> --reason \\"...\\"" if this is an emergency.'));
|
|
835
705
|
await setSoftLock2("Sentinel Mode: Governance Violations Detected", "ARC-VIOLATION", rootPath);
|
|
836
706
|
}
|
|
837
707
|
}
|
|
@@ -854,20 +724,20 @@ async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
|
854
724
|
}, {
|
|
855
725
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
856
726
|
});
|
|
857
|
-
console.log(
|
|
727
|
+
console.log(import_chalk10.default.dim("\u2714 Violations synced to Rigstate Cloud."));
|
|
858
728
|
} catch (e) {
|
|
859
|
-
console.log(
|
|
729
|
+
console.log(import_chalk10.default.dim("\u26A0 Cloud sync skipped: " + (e.message || "Unknown")));
|
|
860
730
|
}
|
|
861
731
|
}
|
|
862
732
|
}
|
|
863
|
-
var
|
|
733
|
+
var import_promises8, import_path8, import_chalk10, import_axios7, DEFAULT_LMAX, DEFAULT_LMAX_WARNING, CACHE_FILE;
|
|
864
734
|
var init_watchdog = __esm({
|
|
865
735
|
"src/utils/watchdog.ts"() {
|
|
866
736
|
"use strict";
|
|
867
737
|
init_cjs_shims();
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
738
|
+
import_promises8 = __toESM(require("fs/promises"), 1);
|
|
739
|
+
import_path8 = __toESM(require("path"), 1);
|
|
740
|
+
import_chalk10 = __toESM(require("chalk"), 1);
|
|
871
741
|
import_axios7 = __toESM(require("axios"), 1);
|
|
872
742
|
init_config();
|
|
873
743
|
DEFAULT_LMAX = 400;
|
|
@@ -1757,7 +1627,7 @@ var require_package = __commonJS({
|
|
|
1757
1627
|
"package.json"(exports2, module2) {
|
|
1758
1628
|
module2.exports = {
|
|
1759
1629
|
name: "@rigstate/cli",
|
|
1760
|
-
version: "0.7.
|
|
1630
|
+
version: "0.7.23",
|
|
1761
1631
|
description: "Rigstate CLI - Code audit, sync and supervision tool",
|
|
1762
1632
|
type: "module",
|
|
1763
1633
|
main: "./dist/index.js",
|
|
@@ -1866,68 +1736,71 @@ Your API key has been securely stored. You can now use "rigstate scan" to audit
|
|
|
1866
1736
|
|
|
1867
1737
|
// src/commands/link.ts
|
|
1868
1738
|
init_cjs_shims();
|
|
1869
|
-
var
|
|
1870
|
-
var
|
|
1871
|
-
var
|
|
1872
|
-
var
|
|
1739
|
+
var import_commander4 = require("commander");
|
|
1740
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
1741
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1742
|
+
var import_chalk5 = __toESM(require("chalk"), 1);
|
|
1873
1743
|
var import_os = __toESM(require("os"), 1);
|
|
1874
1744
|
init_config();
|
|
1875
1745
|
function createLinkCommand() {
|
|
1876
|
-
return new
|
|
1746
|
+
return new import_commander4.Command("link").description("Link current directory to a Rigstate project").argument("<projectId>", "Project ID to link").action(async (projectId) => {
|
|
1877
1747
|
try {
|
|
1878
|
-
const globalPath =
|
|
1879
|
-
const globalData = await
|
|
1748
|
+
const globalPath = import_path2.default.join(import_os.default.homedir(), ".rigstate", "config.json");
|
|
1749
|
+
const globalData = await import_promises2.default.readFile(globalPath, "utf-8").catch(() => null);
|
|
1880
1750
|
if (globalData) {
|
|
1881
1751
|
const config2 = JSON.parse(globalData);
|
|
1882
1752
|
const cwd = process.cwd();
|
|
1883
1753
|
if (config2.overrides && config2.overrides[cwd]) {
|
|
1884
1754
|
const overrideId = config2.overrides[cwd];
|
|
1885
1755
|
if (overrideId !== projectId) {
|
|
1886
|
-
console.warn(
|
|
1756
|
+
console.warn(import_chalk5.default.yellow(`Global override detected. Enforcing project ID: ${overrideId}`));
|
|
1887
1757
|
projectId = overrideId;
|
|
1888
1758
|
}
|
|
1889
1759
|
}
|
|
1890
1760
|
}
|
|
1891
1761
|
} catch (e) {
|
|
1892
1762
|
}
|
|
1893
|
-
const manifestPath =
|
|
1763
|
+
const manifestPath = import_path2.default.join(process.cwd(), ".rigstate");
|
|
1894
1764
|
const content = {
|
|
1895
1765
|
project_id: projectId,
|
|
1896
|
-
api_url: getApiUrl(),
|
|
1897
1766
|
linked_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1898
1767
|
};
|
|
1768
|
+
const currentUrl = getApiUrl();
|
|
1769
|
+
if (currentUrl !== "https://app.rigstate.com") {
|
|
1770
|
+
content.api_url = currentUrl;
|
|
1771
|
+
}
|
|
1899
1772
|
try {
|
|
1900
|
-
await
|
|
1901
|
-
console.log(
|
|
1902
|
-
console.log(
|
|
1773
|
+
await import_promises2.default.writeFile(manifestPath, JSON.stringify(content, null, 2), "utf-8");
|
|
1774
|
+
console.log(import_chalk5.default.green(`\u2714 Linked to project ID: ${projectId}`));
|
|
1775
|
+
console.log(import_chalk5.default.dim(`Created local context manifest at .rigstate`));
|
|
1903
1776
|
console.log("");
|
|
1904
|
-
console.log(
|
|
1777
|
+
console.log(import_chalk5.default.bold("\u{1F916} Rigstate Automation Detected"));
|
|
1905
1778
|
console.log("");
|
|
1906
1779
|
const { getApiKey: _getApiKey, getApiUrl: _getApiUrl } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
1907
1780
|
const apiKey = getApiKey();
|
|
1908
1781
|
const apiUrl = getApiUrl();
|
|
1909
1782
|
if (apiKey) {
|
|
1910
|
-
console.log(
|
|
1783
|
+
console.log(import_chalk5.default.blue("\u{1F510} Checking Vault for secrets..."));
|
|
1911
1784
|
const { syncEnv: syncEnv2 } = await Promise.resolve().then(() => (init_env(), env_exports));
|
|
1912
1785
|
await syncEnv2(projectId, apiKey, apiUrl, true);
|
|
1913
|
-
console.log(
|
|
1786
|
+
console.log(import_chalk5.default.blue("\u{1F9E0} Syncing neural instructions..."));
|
|
1914
1787
|
const { syncProjectRules: syncProjectRules2 } = await Promise.resolve().then(() => (init_sync_rules(), sync_rules_exports));
|
|
1915
1788
|
await syncProjectRules2(projectId, apiKey, apiUrl);
|
|
1916
|
-
console.log(
|
|
1789
|
+
console.log(import_chalk5.default.blue("\u{1F6E1}\uFE0F Checking immunity system..."));
|
|
1917
1790
|
await installHooks(process.cwd());
|
|
1918
1791
|
console.log("");
|
|
1919
|
-
console.log(
|
|
1792
|
+
console.log(import_chalk5.default.bold.green("\u{1F680} Link Complete! Your environment is ready."));
|
|
1920
1793
|
const { suggestNextMove: suggestNextMove2 } = await Promise.resolve().then(() => (init_suggest(), suggest_exports));
|
|
1921
1794
|
await suggestNextMove2(projectId, apiKey, apiUrl);
|
|
1922
1795
|
} else {
|
|
1923
1796
|
console.log("");
|
|
1924
|
-
console.log(
|
|
1797
|
+
console.log(import_chalk5.default.bold.green("\u{1F680} Link Complete!"));
|
|
1925
1798
|
}
|
|
1926
1799
|
} catch (error) {
|
|
1927
1800
|
if (error.message.includes("Not authenticated")) {
|
|
1928
|
-
console.warn(
|
|
1801
|
+
console.warn(import_chalk5.default.yellow('\u26A0\uFE0F Not authenticated. Run "rigstate login" to enable automation features.'));
|
|
1929
1802
|
} else {
|
|
1930
|
-
console.error(
|
|
1803
|
+
console.error(import_chalk5.default.red(`Failed to link project: ${error.message}`));
|
|
1931
1804
|
}
|
|
1932
1805
|
}
|
|
1933
1806
|
});
|
|
@@ -1938,18 +1811,17 @@ async function installHooks(cwd) {
|
|
|
1938
1811
|
try {
|
|
1939
1812
|
await fs23.access(path24.join(cwd, ".git"));
|
|
1940
1813
|
} catch {
|
|
1941
|
-
console.log(
|
|
1814
|
+
console.log(import_chalk5.default.dim(" (Not a git repository, skipping hooks)"));
|
|
1942
1815
|
return;
|
|
1943
1816
|
}
|
|
1944
1817
|
const hooksDir = path24.join(cwd, ".husky");
|
|
1945
1818
|
try {
|
|
1946
|
-
const { installHooks: runInstall } = await Promise.resolve().then(() => (init_hooks(), hooks_exports));
|
|
1947
1819
|
const preCommitPath = path24.join(cwd, ".git/hooks/pre-commit");
|
|
1948
1820
|
try {
|
|
1949
1821
|
await fs23.access(preCommitPath);
|
|
1950
|
-
console.log(
|
|
1822
|
+
console.log(import_chalk5.default.green(" \u2714 Git hooks already active"));
|
|
1951
1823
|
} catch {
|
|
1952
|
-
console.log(
|
|
1824
|
+
console.log(import_chalk5.default.yellow(' \u26A0\uFE0F Git hooks missing. Run "rigstate hooks install" to secure repo.'));
|
|
1953
1825
|
}
|
|
1954
1826
|
} catch (e) {
|
|
1955
1827
|
}
|
|
@@ -1957,23 +1829,23 @@ async function installHooks(cwd) {
|
|
|
1957
1829
|
|
|
1958
1830
|
// src/commands/scan.ts
|
|
1959
1831
|
init_cjs_shims();
|
|
1960
|
-
var
|
|
1961
|
-
var
|
|
1832
|
+
var import_commander5 = require("commander");
|
|
1833
|
+
var import_chalk6 = __toESM(require("chalk"), 1);
|
|
1962
1834
|
var import_ora3 = __toESM(require("ora"), 1);
|
|
1963
1835
|
var import_axios4 = __toESM(require("axios"), 1);
|
|
1964
1836
|
var import_glob = require("glob");
|
|
1965
|
-
var
|
|
1966
|
-
var
|
|
1837
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1838
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
1967
1839
|
init_config();
|
|
1968
1840
|
|
|
1969
1841
|
// src/utils/files.ts
|
|
1970
1842
|
init_cjs_shims();
|
|
1971
|
-
var
|
|
1972
|
-
var
|
|
1843
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1844
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
1973
1845
|
async function readGitignore(dir) {
|
|
1974
|
-
const gitignorePath =
|
|
1846
|
+
const gitignorePath = import_path3.default.join(dir, ".gitignore");
|
|
1975
1847
|
try {
|
|
1976
|
-
const content = await
|
|
1848
|
+
const content = await import_promises3.default.readFile(gitignorePath, "utf-8");
|
|
1977
1849
|
return content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
1978
1850
|
} catch (error) {
|
|
1979
1851
|
return [];
|
|
@@ -2035,13 +1907,13 @@ function isCodeFile(filePath) {
|
|
|
2035
1907
|
".vue",
|
|
2036
1908
|
".svelte"
|
|
2037
1909
|
];
|
|
2038
|
-
const ext =
|
|
1910
|
+
const ext = import_path3.default.extname(filePath).toLowerCase();
|
|
2039
1911
|
return codeExtensions.includes(ext);
|
|
2040
1912
|
}
|
|
2041
1913
|
|
|
2042
1914
|
// src/commands/scan.ts
|
|
2043
1915
|
function createScanCommand() {
|
|
2044
|
-
return new
|
|
1916
|
+
return new import_commander5.Command("scan").description("Scan code files for security and quality issues").argument("[path]", "Directory or file to scan", ".").option("--json", "Output results as JSON").option("--project <id>", "Project ID to associate with this scan").action(async (targetPath, options) => {
|
|
2045
1917
|
const spinner = (0, import_ora3.default)();
|
|
2046
1918
|
try {
|
|
2047
1919
|
const apiKey = getApiKey();
|
|
@@ -2049,26 +1921,26 @@ function createScanCommand() {
|
|
|
2049
1921
|
const projectId = options.project || getProjectId();
|
|
2050
1922
|
if (!projectId) {
|
|
2051
1923
|
console.warn(
|
|
2052
|
-
|
|
1924
|
+
import_chalk6.default.yellow(
|
|
2053
1925
|
"\u26A0\uFE0F No project ID specified. Use --project <id> or set a default."
|
|
2054
1926
|
)
|
|
2055
1927
|
);
|
|
2056
1928
|
}
|
|
2057
|
-
const scanPath =
|
|
2058
|
-
spinner.start(`Scanning ${
|
|
1929
|
+
const scanPath = import_path4.default.resolve(process.cwd(), targetPath);
|
|
1930
|
+
spinner.start(`Scanning ${import_chalk6.default.cyan(scanPath)}...`);
|
|
2059
1931
|
const gitignorePatterns = await readGitignore(scanPath);
|
|
2060
|
-
const pattern =
|
|
1932
|
+
const pattern = import_path4.default.join(scanPath, "**/*");
|
|
2061
1933
|
const allFiles = await (0, import_glob.glob)(pattern, {
|
|
2062
1934
|
nodir: true,
|
|
2063
1935
|
dot: false,
|
|
2064
1936
|
ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/build/**"]
|
|
2065
1937
|
});
|
|
2066
1938
|
const codeFiles = allFiles.filter((file) => {
|
|
2067
|
-
const relativePath =
|
|
1939
|
+
const relativePath = import_path4.default.relative(scanPath, file);
|
|
2068
1940
|
return isCodeFile(file) && !shouldIgnore(relativePath, gitignorePatterns);
|
|
2069
1941
|
});
|
|
2070
1942
|
if (codeFiles.length === 0) {
|
|
2071
|
-
spinner.warn(
|
|
1943
|
+
spinner.warn(import_chalk6.default.yellow("No code files found to scan."));
|
|
2072
1944
|
return;
|
|
2073
1945
|
}
|
|
2074
1946
|
spinner.text = `Found ${codeFiles.length} files. Scanning...`;
|
|
@@ -2077,10 +1949,10 @@ function createScanCommand() {
|
|
|
2077
1949
|
const severityCounts = {};
|
|
2078
1950
|
for (let i = 0; i < codeFiles.length; i++) {
|
|
2079
1951
|
const filePath = codeFiles[i];
|
|
2080
|
-
const relativePath =
|
|
1952
|
+
const relativePath = import_path4.default.relative(scanPath, filePath);
|
|
2081
1953
|
spinner.text = `Scanning ${i + 1}/${codeFiles.length}: ${relativePath}`;
|
|
2082
1954
|
try {
|
|
2083
|
-
const content = await
|
|
1955
|
+
const content = await import_promises4.default.readFile(filePath, "utf-8");
|
|
2084
1956
|
const response = await import_axios4.default.post(
|
|
2085
1957
|
`${apiUrl}/api/v1/audit`,
|
|
2086
1958
|
{
|
|
@@ -2116,15 +1988,15 @@ function createScanCommand() {
|
|
|
2116
1988
|
}
|
|
2117
1989
|
} catch (fileError) {
|
|
2118
1990
|
if (import_axios4.default.isAxiosError(fileError)) {
|
|
2119
|
-
console.warn(
|
|
1991
|
+
console.warn(import_chalk6.default.yellow(`
|
|
2120
1992
|
\u26A0\uFE0F Skipping ${relativePath}: ${fileError.message}`));
|
|
2121
1993
|
} else {
|
|
2122
|
-
console.warn(
|
|
1994
|
+
console.warn(import_chalk6.default.yellow(`
|
|
2123
1995
|
\u26A0\uFE0F Error reading ${relativePath}`));
|
|
2124
1996
|
}
|
|
2125
1997
|
}
|
|
2126
1998
|
}
|
|
2127
|
-
spinner.succeed(
|
|
1999
|
+
spinner.succeed(import_chalk6.default.green("\u2705 Scan completed!"));
|
|
2128
2000
|
const aggregatedResponse = {
|
|
2129
2001
|
results,
|
|
2130
2002
|
summary: {
|
|
@@ -2139,21 +2011,21 @@ function createScanCommand() {
|
|
|
2139
2011
|
printPrettyResults(aggregatedResponse);
|
|
2140
2012
|
}
|
|
2141
2013
|
} catch (error) {
|
|
2142
|
-
spinner.fail(
|
|
2014
|
+
spinner.fail(import_chalk6.default.red("\u274C Scan failed"));
|
|
2143
2015
|
if (import_axios4.default.isAxiosError(error)) {
|
|
2144
2016
|
if (error.response) {
|
|
2145
|
-
console.error(
|
|
2017
|
+
console.error(import_chalk6.default.red("API Error:"), error.response.data);
|
|
2146
2018
|
} else if (error.request) {
|
|
2147
2019
|
console.error(
|
|
2148
|
-
|
|
2020
|
+
import_chalk6.default.red("Network Error:"),
|
|
2149
2021
|
"Could not reach the API. Is the server running?"
|
|
2150
2022
|
);
|
|
2151
2023
|
} else {
|
|
2152
|
-
console.error(
|
|
2024
|
+
console.error(import_chalk6.default.red("Error:"), error.message);
|
|
2153
2025
|
}
|
|
2154
2026
|
} else {
|
|
2155
2027
|
console.error(
|
|
2156
|
-
|
|
2028
|
+
import_chalk6.default.red("Error:"),
|
|
2157
2029
|
error instanceof Error ? error.message : "Unknown error"
|
|
2158
2030
|
);
|
|
2159
2031
|
}
|
|
@@ -2163,10 +2035,10 @@ function createScanCommand() {
|
|
|
2163
2035
|
}
|
|
2164
2036
|
function printPrettyResults(data) {
|
|
2165
2037
|
const { results, summary } = data;
|
|
2166
|
-
console.log("\n" +
|
|
2167
|
-
console.log(
|
|
2168
|
-
console.log(`Total Files Scanned: ${
|
|
2169
|
-
console.log(`Total Issues Found: ${
|
|
2038
|
+
console.log("\n" + import_chalk6.default.bold("\u{1F4CA} Scan Summary"));
|
|
2039
|
+
console.log(import_chalk6.default.dim("\u2500".repeat(60)));
|
|
2040
|
+
console.log(`Total Files Scanned: ${import_chalk6.default.cyan(summary.total_files)}`);
|
|
2041
|
+
console.log(`Total Issues Found: ${import_chalk6.default.yellow(summary.total_issues)}`);
|
|
2170
2042
|
if (summary.by_severity) {
|
|
2171
2043
|
console.log("\nIssues by Severity:");
|
|
2172
2044
|
Object.entries(summary.by_severity).forEach(([severity, count]) => {
|
|
@@ -2175,87 +2047,87 @@ function printPrettyResults(data) {
|
|
|
2175
2047
|
});
|
|
2176
2048
|
}
|
|
2177
2049
|
if (results && results.length > 0) {
|
|
2178
|
-
console.log("\n" +
|
|
2179
|
-
console.log(
|
|
2050
|
+
console.log("\n" + import_chalk6.default.bold("\u{1F50D} Detailed Results"));
|
|
2051
|
+
console.log(import_chalk6.default.dim("\u2500".repeat(60)));
|
|
2180
2052
|
results.forEach((result) => {
|
|
2181
2053
|
if (result.issues && result.issues.length > 0) {
|
|
2182
2054
|
console.log(`
|
|
2183
|
-
${
|
|
2055
|
+
${import_chalk6.default.bold(result.file_path)}`);
|
|
2184
2056
|
result.issues.forEach((issue) => {
|
|
2185
2057
|
const severityColor = getSeverityColor(issue.severity);
|
|
2186
|
-
const lineInfo = issue.line ?
|
|
2058
|
+
const lineInfo = issue.line ? import_chalk6.default.dim(`:${issue.line}`) : "";
|
|
2187
2059
|
console.log(
|
|
2188
2060
|
` ${severityColor(`[${issue.severity.toUpperCase()}]`)} ${issue.type}${lineInfo}`
|
|
2189
2061
|
);
|
|
2190
|
-
console.log(` ${
|
|
2062
|
+
console.log(` ${import_chalk6.default.dim(issue.message)}`);
|
|
2191
2063
|
});
|
|
2192
2064
|
}
|
|
2193
2065
|
});
|
|
2194
2066
|
}
|
|
2195
|
-
console.log("\n" +
|
|
2067
|
+
console.log("\n" + import_chalk6.default.dim("\u2500".repeat(60)));
|
|
2196
2068
|
}
|
|
2197
2069
|
function getSeverityColor(severity) {
|
|
2198
2070
|
switch (severity.toLowerCase()) {
|
|
2199
2071
|
case "critical":
|
|
2200
|
-
return
|
|
2072
|
+
return import_chalk6.default.red.bold;
|
|
2201
2073
|
case "high":
|
|
2202
|
-
return
|
|
2074
|
+
return import_chalk6.default.red;
|
|
2203
2075
|
case "medium":
|
|
2204
|
-
return
|
|
2076
|
+
return import_chalk6.default.yellow;
|
|
2205
2077
|
case "low":
|
|
2206
|
-
return
|
|
2078
|
+
return import_chalk6.default.blue;
|
|
2207
2079
|
case "info":
|
|
2208
|
-
return
|
|
2080
|
+
return import_chalk6.default.gray;
|
|
2209
2081
|
default:
|
|
2210
|
-
return
|
|
2082
|
+
return import_chalk6.default.white;
|
|
2211
2083
|
}
|
|
2212
2084
|
}
|
|
2213
2085
|
|
|
2214
2086
|
// src/commands/fix.ts
|
|
2215
2087
|
init_cjs_shims();
|
|
2216
|
-
var
|
|
2217
|
-
var
|
|
2088
|
+
var import_commander6 = require("commander");
|
|
2089
|
+
var import_chalk7 = __toESM(require("chalk"), 1);
|
|
2218
2090
|
var import_ora4 = __toESM(require("ora"), 1);
|
|
2219
2091
|
var import_axios5 = __toESM(require("axios"), 1);
|
|
2220
2092
|
var import_glob2 = require("glob");
|
|
2221
|
-
var
|
|
2222
|
-
var
|
|
2093
|
+
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
2094
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
2223
2095
|
var import_inquirer = __toESM(require("inquirer"), 1);
|
|
2224
2096
|
var Diff = __toESM(require("diff"), 1);
|
|
2225
2097
|
init_config();
|
|
2226
2098
|
function createFixCommand() {
|
|
2227
|
-
return new
|
|
2099
|
+
return new import_commander6.Command("fix").description("Scan and interactively FIX detected issues using Rigstate AI").argument("[path]", "Directory or file to scan", ".").option("--project <id>", "Project ID to context-aware audit").action(async (targetPath, options) => {
|
|
2228
2100
|
const spinner = (0, import_ora4.default)();
|
|
2229
2101
|
try {
|
|
2230
2102
|
const apiKey = getApiKey();
|
|
2231
2103
|
const apiUrl = getApiUrl();
|
|
2232
2104
|
const projectId = options.project || getProjectId();
|
|
2233
2105
|
if (!projectId) {
|
|
2234
|
-
console.log(
|
|
2106
|
+
console.log(import_chalk7.default.yellow("\u26A0\uFE0F Project ID is required for fixing. Using default or pass --project <id>"));
|
|
2235
2107
|
}
|
|
2236
|
-
const scanPath =
|
|
2108
|
+
const scanPath = import_path5.default.resolve(process.cwd(), targetPath);
|
|
2237
2109
|
const gitignorePatterns = await readGitignore(scanPath);
|
|
2238
|
-
const pattern =
|
|
2110
|
+
const pattern = import_path5.default.join(scanPath, "**/*");
|
|
2239
2111
|
const allFiles = await (0, import_glob2.glob)(pattern, { nodir: true, dot: false, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
2240
2112
|
const codeFiles = allFiles.filter((file) => {
|
|
2241
|
-
const relativePath =
|
|
2113
|
+
const relativePath = import_path5.default.relative(scanPath, file);
|
|
2242
2114
|
return isCodeFile(file) && !shouldIgnore(relativePath, gitignorePatterns);
|
|
2243
2115
|
});
|
|
2244
2116
|
if (codeFiles.length === 0) {
|
|
2245
|
-
console.log(
|
|
2117
|
+
console.log(import_chalk7.default.yellow("No code files found."));
|
|
2246
2118
|
return;
|
|
2247
2119
|
}
|
|
2248
|
-
console.log(
|
|
2120
|
+
console.log(import_chalk7.default.bold(`
|
|
2249
2121
|
\u{1F9E0} Rigstate Fix Mode`));
|
|
2250
|
-
console.log(
|
|
2122
|
+
console.log(import_chalk7.default.dim(`Scanning ${codeFiles.length} files with Project Context...
|
|
2251
2123
|
`));
|
|
2252
2124
|
let fixedCount = 0;
|
|
2253
2125
|
for (let i = 0; i < codeFiles.length; i++) {
|
|
2254
2126
|
const filePath = codeFiles[i];
|
|
2255
|
-
const relativePath =
|
|
2127
|
+
const relativePath = import_path5.default.relative(scanPath, filePath);
|
|
2256
2128
|
spinner.start(`Analyzing ${relativePath}...`);
|
|
2257
2129
|
try {
|
|
2258
|
-
const content = await
|
|
2130
|
+
const content = await import_promises5.default.readFile(filePath, "utf-8");
|
|
2259
2131
|
const response = await import_axios5.default.post(
|
|
2260
2132
|
`${apiUrl}/api/v1/audit`,
|
|
2261
2133
|
{ content, file_path: relativePath, project_id: projectId },
|
|
@@ -2266,22 +2138,22 @@ function createFixCommand() {
|
|
|
2266
2138
|
if (fixableIssues.length > 0) {
|
|
2267
2139
|
spinner.stop();
|
|
2268
2140
|
console.log(`
|
|
2269
|
-
${
|
|
2141
|
+
${import_chalk7.default.bold(relativePath)}: Found ${fixableIssues.length} fixable issues.`);
|
|
2270
2142
|
for (const issue of fixableIssues) {
|
|
2271
|
-
console.log(
|
|
2143
|
+
console.log(import_chalk7.default.red(`
|
|
2272
2144
|
[${issue.type}] ${issue.title}`));
|
|
2273
|
-
console.log(
|
|
2145
|
+
console.log(import_chalk7.default.dim(issue.suggestion || issue.message));
|
|
2274
2146
|
const diff = Diff.createTwoFilesPatch(relativePath, relativePath, content, issue.fixed_content, "Current", "Fixed");
|
|
2275
2147
|
console.log("\n" + diff.split("\n").slice(0, 15).join("\n") + (diff.split("\n").length > 15 ? "\n..." : ""));
|
|
2276
2148
|
const { apply } = await import_inquirer.default.prompt([{
|
|
2277
2149
|
type: "confirm",
|
|
2278
2150
|
name: "apply",
|
|
2279
|
-
message: `Apply this fix to ${
|
|
2151
|
+
message: `Apply this fix to ${import_chalk7.default.cyan(relativePath)}?`,
|
|
2280
2152
|
default: true
|
|
2281
2153
|
}]);
|
|
2282
2154
|
if (apply) {
|
|
2283
|
-
await
|
|
2284
|
-
console.log(
|
|
2155
|
+
await import_promises5.default.writeFile(filePath, issue.fixed_content);
|
|
2156
|
+
console.log(import_chalk7.default.green(`\u2705 Fixed applied!`));
|
|
2285
2157
|
fixedCount++;
|
|
2286
2158
|
if (issue.related_step_id) {
|
|
2287
2159
|
const { completeStep } = await import_inquirer.default.prompt([{
|
|
@@ -2297,15 +2169,15 @@ ${import_chalk8.default.bold(relativePath)}: Found ${fixableIssues.length} fixab
|
|
|
2297
2169
|
{ step_id: issue.related_step_id, status: "COMPLETED", project_id: projectId },
|
|
2298
2170
|
{ headers: { "Authorization": `Bearer ${apiKey}` } }
|
|
2299
2171
|
);
|
|
2300
|
-
console.log(
|
|
2172
|
+
console.log(import_chalk7.default.green(`\u{1F680} Roadmap updated! Mission Control is in sync.`));
|
|
2301
2173
|
} catch (err) {
|
|
2302
|
-
console.error(
|
|
2174
|
+
console.error(import_chalk7.default.yellow(`Failed to update roadmap: ${err.message}`));
|
|
2303
2175
|
}
|
|
2304
2176
|
}
|
|
2305
2177
|
}
|
|
2306
2178
|
break;
|
|
2307
2179
|
} else {
|
|
2308
|
-
console.log(
|
|
2180
|
+
console.log(import_chalk7.default.dim("Skipped."));
|
|
2309
2181
|
}
|
|
2310
2182
|
}
|
|
2311
2183
|
} else {
|
|
@@ -2315,11 +2187,11 @@ ${import_chalk8.default.bold(relativePath)}: Found ${fixableIssues.length} fixab
|
|
|
2315
2187
|
}
|
|
2316
2188
|
}
|
|
2317
2189
|
spinner.stop();
|
|
2318
|
-
console.log(
|
|
2190
|
+
console.log(import_chalk7.default.bold.green(`
|
|
2319
2191
|
|
|
2320
2192
|
\u{1F680} Fix session complete!`));
|
|
2321
2193
|
console.log(`Frank fixed ${fixedCount} detected issues.`);
|
|
2322
|
-
console.log(
|
|
2194
|
+
console.log(import_chalk7.default.dim(`Run 'rigstate scan' to verify remaining issues.`));
|
|
2323
2195
|
} catch (error) {
|
|
2324
2196
|
spinner.fail("Fix session failed");
|
|
2325
2197
|
console.error(error.message);
|
|
@@ -2329,15 +2201,15 @@ ${import_chalk8.default.bold(relativePath)}: Found ${fixableIssues.length} fixab
|
|
|
2329
2201
|
|
|
2330
2202
|
// src/commands/sync.ts
|
|
2331
2203
|
init_cjs_shims();
|
|
2332
|
-
var
|
|
2333
|
-
var
|
|
2204
|
+
var import_commander7 = require("commander");
|
|
2205
|
+
var import_chalk11 = __toESM(require("chalk"), 1);
|
|
2334
2206
|
var import_ora5 = __toESM(require("ora"), 1);
|
|
2335
2207
|
init_config();
|
|
2336
2208
|
var import_axios8 = __toESM(require("axios"), 1);
|
|
2337
|
-
var
|
|
2338
|
-
var
|
|
2209
|
+
var import_promises9 = __toESM(require("fs/promises"), 1);
|
|
2210
|
+
var import_path9 = __toESM(require("path"), 1);
|
|
2339
2211
|
function createSyncCommand() {
|
|
2340
|
-
const sync = new
|
|
2212
|
+
const sync = new import_commander7.Command("sync");
|
|
2341
2213
|
sync.description("Synchronize local state with Rigstate Cloud").option("-p, --project <id>", "Specify Project ID (saves to config automatically)").action(async (options) => {
|
|
2342
2214
|
const spinner = (0, import_ora5.default)("Synchronizing project state...").start();
|
|
2343
2215
|
try {
|
|
@@ -2351,8 +2223,8 @@ function createSyncCommand() {
|
|
|
2351
2223
|
let projectId = options.project;
|
|
2352
2224
|
if (!projectId) {
|
|
2353
2225
|
try {
|
|
2354
|
-
const manifestPath =
|
|
2355
|
-
const manifestContent = await
|
|
2226
|
+
const manifestPath = import_path9.default.join(process.cwd(), ".rigstate");
|
|
2227
|
+
const manifestContent = await import_promises9.default.readFile(manifestPath, "utf-8");
|
|
2356
2228
|
const manifest = JSON.parse(manifestContent);
|
|
2357
2229
|
if (manifest.project_id) projectId = manifest.project_id;
|
|
2358
2230
|
} catch (e) {
|
|
@@ -2376,31 +2248,31 @@ function createSyncCommand() {
|
|
|
2376
2248
|
}
|
|
2377
2249
|
const { roadmap, project } = response.data.data;
|
|
2378
2250
|
const timestamp = response.data.timestamp;
|
|
2379
|
-
const targetPath =
|
|
2251
|
+
const targetPath = import_path9.default.join(process.cwd(), "roadmap.json");
|
|
2380
2252
|
const fileContent = JSON.stringify({
|
|
2381
2253
|
project,
|
|
2382
2254
|
last_synced: timestamp,
|
|
2383
2255
|
roadmap
|
|
2384
2256
|
}, null, 2);
|
|
2385
|
-
await
|
|
2257
|
+
await import_promises9.default.writeFile(targetPath, fileContent, "utf-8");
|
|
2386
2258
|
try {
|
|
2387
|
-
const manifestPath =
|
|
2259
|
+
const manifestPath = import_path9.default.join(process.cwd(), ".rigstate");
|
|
2388
2260
|
const manifestContent = {
|
|
2389
2261
|
project_id: projectId,
|
|
2390
2262
|
project_name: project,
|
|
2391
2263
|
last_synced: timestamp,
|
|
2392
2264
|
api_url: apiUrl
|
|
2393
2265
|
};
|
|
2394
|
-
await
|
|
2266
|
+
await import_promises9.default.writeFile(manifestPath, JSON.stringify(manifestContent, null, 2), "utf-8");
|
|
2395
2267
|
} catch (e) {
|
|
2396
2268
|
}
|
|
2397
|
-
console.log(
|
|
2269
|
+
console.log(import_chalk11.default.bold("\n\u{1F9E0} Agent Skills Provisioning..."));
|
|
2398
2270
|
try {
|
|
2399
2271
|
const { provisionSkills: provisionSkills2, generateSkillsDiscoveryBlock: generateSkillsDiscoveryBlock2 } = await Promise.resolve().then(() => (init_skills_provisioner(), skills_provisioner_exports));
|
|
2400
2272
|
const skills = await provisionSkills2(apiUrl, apiKey, projectId, process.cwd());
|
|
2401
|
-
const cursorRulesPath =
|
|
2273
|
+
const cursorRulesPath = import_path9.default.join(process.cwd(), ".cursorrules");
|
|
2402
2274
|
try {
|
|
2403
|
-
let rulesContent = await
|
|
2275
|
+
let rulesContent = await import_promises9.default.readFile(cursorRulesPath, "utf-8");
|
|
2404
2276
|
const skillsBlock = generateSkillsDiscoveryBlock2(skills);
|
|
2405
2277
|
if (rulesContent.includes("<available_skills>")) {
|
|
2406
2278
|
rulesContent = rulesContent.replace(
|
|
@@ -2413,17 +2285,17 @@ function createSyncCommand() {
|
|
|
2413
2285
|
rulesContent = rulesContent.slice(0, insertPoint + 3) + "\n\n" + skillsBlock + "\n" + rulesContent.slice(insertPoint + 3);
|
|
2414
2286
|
}
|
|
2415
2287
|
}
|
|
2416
|
-
await
|
|
2417
|
-
console.log(
|
|
2288
|
+
await import_promises9.default.writeFile(cursorRulesPath, rulesContent, "utf-8");
|
|
2289
|
+
console.log(import_chalk11.default.dim(` Updated .cursorrules with skills discovery block`));
|
|
2418
2290
|
} catch (e) {
|
|
2419
2291
|
}
|
|
2420
2292
|
} catch (e) {
|
|
2421
|
-
console.log(
|
|
2293
|
+
console.log(import_chalk11.default.yellow(` \u26A0 Skills provisioning skipped: ${e.message}`));
|
|
2422
2294
|
}
|
|
2423
2295
|
try {
|
|
2424
|
-
const logPath =
|
|
2296
|
+
const logPath = import_path9.default.join(process.cwd(), ".rigstate", "logs", "last_execution.json");
|
|
2425
2297
|
try {
|
|
2426
|
-
const logContent = await
|
|
2298
|
+
const logContent = await import_promises9.default.readFile(logPath, "utf-8");
|
|
2427
2299
|
const logData = JSON.parse(logContent);
|
|
2428
2300
|
if (logData.task_summary) {
|
|
2429
2301
|
await import_axios8.default.post(`${apiUrl}/api/v1/execution-logs`, {
|
|
@@ -2433,8 +2305,8 @@ function createSyncCommand() {
|
|
|
2433
2305
|
}, {
|
|
2434
2306
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
2435
2307
|
});
|
|
2436
|
-
await
|
|
2437
|
-
console.log(
|
|
2308
|
+
await import_promises9.default.unlink(logPath);
|
|
2309
|
+
console.log(import_chalk11.default.dim(`\u2714 Mission Report uploaded.`));
|
|
2438
2310
|
}
|
|
2439
2311
|
} catch (e) {
|
|
2440
2312
|
if (e.code !== "ENOENT") {
|
|
@@ -2442,12 +2314,12 @@ function createSyncCommand() {
|
|
|
2442
2314
|
}
|
|
2443
2315
|
} catch (e) {
|
|
2444
2316
|
}
|
|
2445
|
-
spinner.succeed(
|
|
2446
|
-
console.log(
|
|
2317
|
+
spinner.succeed(import_chalk11.default.green(`Synced ${roadmap.length} roadmap steps for project "${project}"`));
|
|
2318
|
+
console.log(import_chalk11.default.dim(`Local files updated: roadmap.json`));
|
|
2447
2319
|
const { runGuardianWatchdog: runGuardianWatchdog2 } = await Promise.resolve().then(() => (init_watchdog(), watchdog_exports));
|
|
2448
2320
|
const settings = response.data.data.settings || {};
|
|
2449
2321
|
await runGuardianWatchdog2(process.cwd(), settings, projectId);
|
|
2450
|
-
console.log(
|
|
2322
|
+
console.log(import_chalk11.default.bold("\n\u{1F4E1} Agent Bridge Heartbeat..."));
|
|
2451
2323
|
try {
|
|
2452
2324
|
const bridgeResponse = await import_axios8.default.get(`${apiUrl}/api/v1/agent/bridge`, {
|
|
2453
2325
|
params: { project_id: projectId },
|
|
@@ -2458,10 +2330,10 @@ function createSyncCommand() {
|
|
|
2458
2330
|
const pending = tasks.filter((t) => t.status === "PENDING");
|
|
2459
2331
|
const approved = tasks.filter((t) => t.status === "APPROVED");
|
|
2460
2332
|
if (pending.length > 0 || approved.length > 0) {
|
|
2461
|
-
console.log(
|
|
2462
|
-
console.log(
|
|
2333
|
+
console.log(import_chalk11.default.yellow(`\u26A0 Bridge Alert: ${pending.length} pending, ${approved.length} approved tasks found.`));
|
|
2334
|
+
console.log(import_chalk11.default.dim('Run "rigstate fix" to process these tasks or ensure your IDE MCP server is active.'));
|
|
2463
2335
|
} else {
|
|
2464
|
-
console.log(
|
|
2336
|
+
console.log(import_chalk11.default.green("\u2714 Heartbeat healthy. No pending bridge tasks."));
|
|
2465
2337
|
}
|
|
2466
2338
|
const pings = pending.filter((t) => t.proposal?.startsWith("ping"));
|
|
2467
2339
|
for (const ping of pings) {
|
|
@@ -2472,25 +2344,25 @@ function createSyncCommand() {
|
|
|
2472
2344
|
}, {
|
|
2473
2345
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
2474
2346
|
});
|
|
2475
|
-
console.log(
|
|
2347
|
+
console.log(import_chalk11.default.cyan(`\u{1F3D3} Pong! Acknowledged heartbeat signal [${ping.id}]`));
|
|
2476
2348
|
}
|
|
2477
2349
|
}
|
|
2478
2350
|
} catch (e) {
|
|
2479
|
-
console.log(
|
|
2351
|
+
console.log(import_chalk11.default.yellow(`\u26A0 Could not verify Bridge status: ${e.message}`));
|
|
2480
2352
|
}
|
|
2481
2353
|
if (options.project) {
|
|
2482
|
-
console.log(
|
|
2354
|
+
console.log(import_chalk11.default.blue(`Project context saved. Future commands will use this project.`));
|
|
2483
2355
|
}
|
|
2484
2356
|
try {
|
|
2485
|
-
const migrationDir =
|
|
2486
|
-
const files = await
|
|
2357
|
+
const migrationDir = import_path9.default.join(process.cwd(), "supabase", "migrations");
|
|
2358
|
+
const files = await import_promises9.default.readdir(migrationDir);
|
|
2487
2359
|
const sqlFiles = files.filter((f) => f.endsWith(".sql")).sort();
|
|
2488
2360
|
if (sqlFiles.length > 0) {
|
|
2489
2361
|
const latestMigration = sqlFiles[sqlFiles.length - 1];
|
|
2490
|
-
console.log(
|
|
2362
|
+
console.log(import_chalk11.default.dim(`
|
|
2491
2363
|
\u{1F6E1} Migration Guard:`));
|
|
2492
|
-
console.log(
|
|
2493
|
-
console.log(
|
|
2364
|
+
console.log(import_chalk11.default.dim(` Latest Local: ${latestMigration}`));
|
|
2365
|
+
console.log(import_chalk11.default.yellow(` \u26A0 Ensure DB schema matches this version. CLI cannot verify Remote RLS policies directly.`));
|
|
2494
2366
|
}
|
|
2495
2367
|
} catch (e) {
|
|
2496
2368
|
}
|
|
@@ -2502,15 +2374,15 @@ function createSyncCommand() {
|
|
|
2502
2374
|
);
|
|
2503
2375
|
if (vaultResponse.data.success) {
|
|
2504
2376
|
const vaultContent = vaultResponse.data.data.content || "";
|
|
2505
|
-
const localEnvPath =
|
|
2377
|
+
const localEnvPath = import_path9.default.join(process.cwd(), ".env.local");
|
|
2506
2378
|
let localContent = "";
|
|
2507
2379
|
try {
|
|
2508
|
-
localContent = await
|
|
2380
|
+
localContent = await import_promises9.default.readFile(localEnvPath, "utf-8");
|
|
2509
2381
|
} catch (e) {
|
|
2510
2382
|
}
|
|
2511
2383
|
if (vaultContent.trim() !== localContent.trim()) {
|
|
2512
|
-
console.log(
|
|
2513
|
-
console.log(
|
|
2384
|
+
console.log(import_chalk11.default.bold("\n\u{1F510} Sovereign Foundation (Vault):"));
|
|
2385
|
+
console.log(import_chalk11.default.yellow(" Status: Drift Detected / Update Available"));
|
|
2514
2386
|
const { syncVault } = await import("inquirer").then((m) => m.default.prompt([{
|
|
2515
2387
|
type: "confirm",
|
|
2516
2388
|
name: "syncVault",
|
|
@@ -2518,25 +2390,25 @@ function createSyncCommand() {
|
|
|
2518
2390
|
default: false
|
|
2519
2391
|
}]));
|
|
2520
2392
|
if (syncVault) {
|
|
2521
|
-
await
|
|
2522
|
-
console.log(
|
|
2393
|
+
await import_promises9.default.writeFile(localEnvPath, vaultContent, "utf-8");
|
|
2394
|
+
console.log(import_chalk11.default.green(" \u2705 .env.local synchronized with Vault."));
|
|
2523
2395
|
} else {
|
|
2524
|
-
console.log(
|
|
2396
|
+
console.log(import_chalk11.default.dim(" Skipped vault sync."));
|
|
2525
2397
|
}
|
|
2526
2398
|
} else {
|
|
2527
|
-
console.log(
|
|
2399
|
+
console.log(import_chalk11.default.dim("\n\u{1F510} Sovereign Foundation: Synced."));
|
|
2528
2400
|
}
|
|
2529
2401
|
}
|
|
2530
2402
|
} catch (e) {
|
|
2531
2403
|
}
|
|
2532
|
-
console.log(
|
|
2404
|
+
console.log(import_chalk11.default.dim("\n\u{1F6E1}\uFE0F System Integrity Check..."));
|
|
2533
2405
|
await checkSystemIntegrity(apiUrl, apiKey, projectId);
|
|
2534
2406
|
} catch (error) {
|
|
2535
2407
|
if (import_axios8.default.isAxiosError(error)) {
|
|
2536
2408
|
const message = error.response?.data?.error || error.message;
|
|
2537
|
-
spinner.fail(
|
|
2409
|
+
spinner.fail(import_chalk11.default.red(`Sync failed: ${message}`));
|
|
2538
2410
|
} else {
|
|
2539
|
-
spinner.fail(
|
|
2411
|
+
spinner.fail(import_chalk11.default.red("Sync failed: " + (error.message || "Unknown error")));
|
|
2540
2412
|
}
|
|
2541
2413
|
}
|
|
2542
2414
|
});
|
|
@@ -2552,57 +2424,57 @@ async function checkSystemIntegrity(apiUrl, apiKey, projectId) {
|
|
|
2552
2424
|
const { migrations, rls, guardian_violations } = response.data.data;
|
|
2553
2425
|
if (migrations) {
|
|
2554
2426
|
if (migrations.in_sync) {
|
|
2555
|
-
console.log(
|
|
2427
|
+
console.log(import_chalk11.default.green(` \u2705 Migrations synced (${migrations.count} versions)`));
|
|
2556
2428
|
} else {
|
|
2557
|
-
console.log(
|
|
2429
|
+
console.log(import_chalk11.default.red(` \u{1F6D1} CRITICAL: DB Schema out of sync! ${migrations.missing?.length || 0} migrations not applied.`));
|
|
2558
2430
|
if (migrations.missing?.length > 0) {
|
|
2559
|
-
console.log(
|
|
2431
|
+
console.log(import_chalk11.default.dim(` Missing: ${migrations.missing.slice(0, 3).join(", ")}${migrations.missing.length > 3 ? "..." : ""}`));
|
|
2560
2432
|
}
|
|
2561
|
-
console.log(
|
|
2433
|
+
console.log(import_chalk11.default.yellow(` Run 'supabase db push' or apply migrations immediately.`));
|
|
2562
2434
|
}
|
|
2563
2435
|
}
|
|
2564
2436
|
if (rls) {
|
|
2565
2437
|
if (rls.all_secured) {
|
|
2566
|
-
console.log(
|
|
2438
|
+
console.log(import_chalk11.default.green(` \u2705 RLS Audit Passed (${rls.table_count} tables secured)`));
|
|
2567
2439
|
} else {
|
|
2568
|
-
console.log(
|
|
2440
|
+
console.log(import_chalk11.default.red(` \u{1F6D1} CRITICAL: Security Vulnerability! ${rls.unsecured?.length || 0} tables have RLS disabled.`));
|
|
2569
2441
|
rls.unsecured?.forEach((table) => {
|
|
2570
|
-
console.log(
|
|
2442
|
+
console.log(import_chalk11.default.red(` - ${table}`));
|
|
2571
2443
|
});
|
|
2572
|
-
console.log(
|
|
2444
|
+
console.log(import_chalk11.default.yellow(' Enable RLS immediately: ALTER TABLE "table" ENABLE ROW LEVEL SECURITY;'));
|
|
2573
2445
|
}
|
|
2574
2446
|
}
|
|
2575
2447
|
if (guardian_violations) {
|
|
2576
2448
|
if (guardian_violations.count === 0) {
|
|
2577
|
-
console.log(
|
|
2449
|
+
console.log(import_chalk11.default.green(" \u2705 Guardian: No active violations"));
|
|
2578
2450
|
} else {
|
|
2579
|
-
console.log(
|
|
2580
|
-
console.log(
|
|
2451
|
+
console.log(import_chalk11.default.yellow(` \u26A0\uFE0F Guardian: ${guardian_violations.count} active violations`));
|
|
2452
|
+
console.log(import_chalk11.default.dim(' Run "rigstate check" for details.'));
|
|
2581
2453
|
}
|
|
2582
2454
|
}
|
|
2583
2455
|
}
|
|
2584
2456
|
} catch (e) {
|
|
2585
|
-
console.log(
|
|
2457
|
+
console.log(import_chalk11.default.dim(" (System integrity check skipped - API endpoint not available)"));
|
|
2586
2458
|
}
|
|
2587
2459
|
}
|
|
2588
2460
|
|
|
2589
2461
|
// src/commands/init.ts
|
|
2590
2462
|
init_cjs_shims();
|
|
2591
|
-
var
|
|
2592
|
-
var
|
|
2593
|
-
var
|
|
2594
|
-
var
|
|
2463
|
+
var import_commander8 = require("commander");
|
|
2464
|
+
var import_chalk12 = __toESM(require("chalk"), 1);
|
|
2465
|
+
var import_promises11 = __toESM(require("fs/promises"), 1);
|
|
2466
|
+
var import_path11 = __toESM(require("path"), 1);
|
|
2595
2467
|
var import_ora6 = __toESM(require("ora"), 1);
|
|
2596
2468
|
var import_child_process = require("child_process");
|
|
2597
2469
|
|
|
2598
2470
|
// src/utils/manifest.ts
|
|
2599
2471
|
init_cjs_shims();
|
|
2600
|
-
var
|
|
2601
|
-
var
|
|
2472
|
+
var import_promises10 = __toESM(require("fs/promises"), 1);
|
|
2473
|
+
var import_path10 = __toESM(require("path"), 1);
|
|
2602
2474
|
async function loadManifest() {
|
|
2603
2475
|
try {
|
|
2604
|
-
const manifestPath =
|
|
2605
|
-
const content = await
|
|
2476
|
+
const manifestPath = import_path10.default.join(process.cwd(), ".rigstate");
|
|
2477
|
+
const content = await import_promises10.default.readFile(manifestPath, "utf-8");
|
|
2606
2478
|
return JSON.parse(content);
|
|
2607
2479
|
} catch {
|
|
2608
2480
|
return null;
|
|
@@ -2613,13 +2485,13 @@ async function loadManifest() {
|
|
|
2613
2485
|
init_config();
|
|
2614
2486
|
var import_axios9 = __toESM(require("axios"), 1);
|
|
2615
2487
|
function createInitCommand() {
|
|
2616
|
-
return new
|
|
2488
|
+
return new import_commander8.Command("init").description("Initialize or link a Rigstate project (interactive mode available)").argument("[project-id]", "ID of the project to link (optional, prompts if not provided)").option("-f, --force", "Overwrite existing .cursorrules file").option("--rules-only", "Only regenerate .cursorrules without interactive setup").action(async (projectIdArg, options) => {
|
|
2617
2489
|
const spinner = (0, import_ora6.default)("Initializing Rigstate project...").start();
|
|
2618
2490
|
let apiKey;
|
|
2619
2491
|
try {
|
|
2620
2492
|
apiKey = getApiKey();
|
|
2621
2493
|
} catch (e) {
|
|
2622
|
-
spinner.fail(
|
|
2494
|
+
spinner.fail(import_chalk12.default.red('Not authenticated. Run "rigstate login" first.'));
|
|
2623
2495
|
return;
|
|
2624
2496
|
}
|
|
2625
2497
|
const apiUrl = getApiUrl();
|
|
@@ -2716,7 +2588,7 @@ function createInitCommand() {
|
|
|
2716
2588
|
selectedOrgId = orgId;
|
|
2717
2589
|
}
|
|
2718
2590
|
if (!selectedOrgId) {
|
|
2719
|
-
console.log(
|
|
2591
|
+
console.log(import_chalk12.default.yellow("No organization available. Please create the project via the Rigstate dashboard."));
|
|
2720
2592
|
return;
|
|
2721
2593
|
}
|
|
2722
2594
|
spinner.start("Creating new project...");
|
|
@@ -2728,13 +2600,13 @@ function createInitCommand() {
|
|
|
2728
2600
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
2729
2601
|
});
|
|
2730
2602
|
if (!createResponse.data.success) {
|
|
2731
|
-
spinner.fail(
|
|
2603
|
+
spinner.fail(import_chalk12.default.red("Failed to create project: " + createResponse.data.error));
|
|
2732
2604
|
return;
|
|
2733
2605
|
}
|
|
2734
2606
|
projectId = createResponse.data.data.project.id;
|
|
2735
|
-
spinner.succeed(
|
|
2607
|
+
spinner.succeed(import_chalk12.default.green(`Created new project: ${newName}`));
|
|
2736
2608
|
} catch (e) {
|
|
2737
|
-
spinner.fail(
|
|
2609
|
+
spinner.fail(import_chalk12.default.red("Project creation API not available. Please create via dashboard."));
|
|
2738
2610
|
return;
|
|
2739
2611
|
}
|
|
2740
2612
|
} else {
|
|
@@ -2744,28 +2616,28 @@ function createInitCommand() {
|
|
|
2744
2616
|
spinner.start(`Linking to project ID: ${projectId}...`);
|
|
2745
2617
|
}
|
|
2746
2618
|
setProjectId(projectId);
|
|
2747
|
-
const manifestPath =
|
|
2619
|
+
const manifestPath = import_path11.default.join(process.cwd(), ".rigstate");
|
|
2748
2620
|
const manifestContent = {
|
|
2749
2621
|
project_id: projectId,
|
|
2750
2622
|
last_linked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2751
2623
|
api_url: apiUrl
|
|
2752
2624
|
};
|
|
2753
|
-
await
|
|
2625
|
+
await import_promises11.default.writeFile(manifestPath, JSON.stringify(manifestContent, null, 2), "utf-8");
|
|
2754
2626
|
try {
|
|
2755
|
-
await
|
|
2627
|
+
await import_promises11.default.access(".git");
|
|
2756
2628
|
} catch {
|
|
2757
2629
|
spinner.text = "Initializing git repository...";
|
|
2758
2630
|
(0, import_child_process.execSync)("git init", { stdio: "ignore" });
|
|
2759
2631
|
}
|
|
2760
|
-
spinner.succeed(
|
|
2632
|
+
spinner.succeed(import_chalk12.default.green(`\u2705 Linked to project: ${projectId}`));
|
|
2761
2633
|
await generateRules(apiUrl, apiKey, projectId, options.force, spinner);
|
|
2762
2634
|
console.log("");
|
|
2763
|
-
console.log(
|
|
2764
|
-
console.log(
|
|
2765
|
-
console.log(
|
|
2766
|
-
console.log(
|
|
2635
|
+
console.log(import_chalk12.default.blue("Next steps:"));
|
|
2636
|
+
console.log(import_chalk12.default.dim(" rigstate sync - Sync roadmap and context"));
|
|
2637
|
+
console.log(import_chalk12.default.dim(" rigstate watch - Start development loop"));
|
|
2638
|
+
console.log(import_chalk12.default.dim(" rigstate focus - Get current task"));
|
|
2767
2639
|
} catch (e) {
|
|
2768
|
-
spinner.fail(
|
|
2640
|
+
spinner.fail(import_chalk12.default.red("Initialization failed: " + e.message));
|
|
2769
2641
|
}
|
|
2770
2642
|
});
|
|
2771
2643
|
}
|
|
@@ -2780,67 +2652,67 @@ async function generateRules(apiUrl, apiKey, projectId, force, spinner) {
|
|
|
2780
2652
|
if (response.data.success || response.data.files) {
|
|
2781
2653
|
const files = response.data.files || [];
|
|
2782
2654
|
if (files.length === 0 && response.data.rules) {
|
|
2783
|
-
const rulesPath =
|
|
2784
|
-
await
|
|
2785
|
-
spinner.succeed(
|
|
2655
|
+
const rulesPath = import_path11.default.join(process.cwd(), ".cursorrules");
|
|
2656
|
+
await import_promises11.default.writeFile(rulesPath, response.data.rules, "utf-8");
|
|
2657
|
+
spinner.succeed(import_chalk12.default.green("\u2714 Generated .cursorrules (legacy mode)"));
|
|
2786
2658
|
return;
|
|
2787
2659
|
}
|
|
2788
2660
|
for (const file of files) {
|
|
2789
|
-
const targetPath =
|
|
2790
|
-
const targetDir =
|
|
2791
|
-
await
|
|
2661
|
+
const targetPath = import_path11.default.join(process.cwd(), file.path);
|
|
2662
|
+
const targetDir = import_path11.default.dirname(targetPath);
|
|
2663
|
+
await import_promises11.default.mkdir(targetDir, { recursive: true });
|
|
2792
2664
|
try {
|
|
2793
|
-
await
|
|
2665
|
+
await import_promises11.default.access(targetPath);
|
|
2794
2666
|
if (!force && !file.path.startsWith(".cursor/rules/")) {
|
|
2795
|
-
console.log(
|
|
2667
|
+
console.log(import_chalk12.default.dim(` ${file.path} already exists. Skipping.`));
|
|
2796
2668
|
continue;
|
|
2797
2669
|
}
|
|
2798
2670
|
} catch {
|
|
2799
2671
|
}
|
|
2800
|
-
await
|
|
2672
|
+
await import_promises11.default.writeFile(targetPath, file.content, "utf-8");
|
|
2801
2673
|
}
|
|
2802
2674
|
if (files.length > 0) {
|
|
2803
|
-
const legacyPath =
|
|
2675
|
+
const legacyPath = import_path11.default.join(process.cwd(), ".cursorrules");
|
|
2804
2676
|
try {
|
|
2805
|
-
const stats = await
|
|
2677
|
+
const stats = await import_promises11.default.stat(legacyPath);
|
|
2806
2678
|
if (stats.isFile()) {
|
|
2807
|
-
await
|
|
2808
|
-
console.log(
|
|
2679
|
+
await import_promises11.default.rename(legacyPath, `${legacyPath}.bak`);
|
|
2680
|
+
console.log(import_chalk12.default.dim(" Moved legacy .cursorrules to .cursorrules.bak"));
|
|
2809
2681
|
}
|
|
2810
2682
|
} catch (e) {
|
|
2811
2683
|
}
|
|
2812
2684
|
}
|
|
2813
|
-
spinner.succeed(
|
|
2685
|
+
spinner.succeed(import_chalk12.default.green(`\u2714 Generated ${files.length} rule files (v${response.data.version || "3.0"})`));
|
|
2814
2686
|
} else {
|
|
2815
|
-
spinner.info(
|
|
2687
|
+
spinner.info(import_chalk12.default.dim(" Rules generation skipped (API response invalid)"));
|
|
2816
2688
|
}
|
|
2817
2689
|
} catch (e) {
|
|
2818
|
-
spinner.info(
|
|
2690
|
+
spinner.info(import_chalk12.default.dim(` Rules generation failed: ${e.message}`));
|
|
2819
2691
|
}
|
|
2820
2692
|
}
|
|
2821
2693
|
|
|
2822
2694
|
// src/commands/check.ts
|
|
2823
2695
|
init_cjs_shims();
|
|
2824
|
-
var
|
|
2825
|
-
var
|
|
2696
|
+
var import_commander9 = require("commander");
|
|
2697
|
+
var import_chalk14 = __toESM(require("chalk"), 1);
|
|
2826
2698
|
var import_ora7 = __toESM(require("ora"), 1);
|
|
2827
2699
|
var import_axios10 = __toESM(require("axios"), 1);
|
|
2828
2700
|
var import_glob3 = require("glob");
|
|
2829
|
-
var
|
|
2830
|
-
var
|
|
2701
|
+
var import_promises13 = __toESM(require("fs/promises"), 1);
|
|
2702
|
+
var import_path13 = __toESM(require("path"), 1);
|
|
2831
2703
|
var import_child_process2 = require("child_process");
|
|
2832
2704
|
init_config();
|
|
2833
2705
|
|
|
2834
2706
|
// src/utils/rule-engine.ts
|
|
2835
2707
|
init_cjs_shims();
|
|
2836
|
-
var
|
|
2837
|
-
var
|
|
2838
|
-
var
|
|
2708
|
+
var import_promises12 = __toESM(require("fs/promises"), 1);
|
|
2709
|
+
var import_path12 = __toESM(require("path"), 1);
|
|
2710
|
+
var import_chalk13 = __toESM(require("chalk"), 1);
|
|
2839
2711
|
async function checkFile(filePath, rules, rootPath) {
|
|
2840
2712
|
const violations = [];
|
|
2841
|
-
const relativePath =
|
|
2713
|
+
const relativePath = import_path12.default.relative(rootPath, filePath);
|
|
2842
2714
|
try {
|
|
2843
|
-
const content = await
|
|
2715
|
+
const content = await import_promises12.default.readFile(filePath, "utf-8");
|
|
2844
2716
|
const lines = content.split("\n");
|
|
2845
2717
|
for (const rule of rules) {
|
|
2846
2718
|
const ruleViolations = await evaluateRule(rule, content, lines, relativePath);
|
|
@@ -2931,7 +2803,7 @@ async function evaluateRule(rule, content, lines, filePath) {
|
|
|
2931
2803
|
case "NAMING_CONVENTION": {
|
|
2932
2804
|
const value = rule.value;
|
|
2933
2805
|
const pattern = new RegExp(value.pattern);
|
|
2934
|
-
const fileName =
|
|
2806
|
+
const fileName = import_path12.default.basename(filePath);
|
|
2935
2807
|
if (filePath.includes(value.context) && !pattern.test(fileName)) {
|
|
2936
2808
|
violations.push({
|
|
2937
2809
|
file: filePath,
|
|
@@ -2990,12 +2862,12 @@ function checkFunctionLines(content, lines, filePath, rule, limit) {
|
|
|
2990
2862
|
}
|
|
2991
2863
|
function formatViolations(violations) {
|
|
2992
2864
|
for (const v of violations) {
|
|
2993
|
-
const severityColor = v.severity === "critical" ?
|
|
2994
|
-
const lineInfo = v.line ?
|
|
2865
|
+
const severityColor = v.severity === "critical" ? import_chalk13.default.red : v.severity === "warning" ? import_chalk13.default.yellow : import_chalk13.default.blue;
|
|
2866
|
+
const lineInfo = v.line ? import_chalk13.default.dim(`:${v.line}`) : "";
|
|
2995
2867
|
console.log(` ${severityColor(`[${v.severity.toUpperCase()}]`)} ${v.file}${lineInfo}`);
|
|
2996
2868
|
console.log(` ${v.message}`);
|
|
2997
2869
|
if (v.details) {
|
|
2998
|
-
console.log(` ${
|
|
2870
|
+
console.log(` ${import_chalk13.default.dim(v.details)}`);
|
|
2999
2871
|
}
|
|
3000
2872
|
}
|
|
3001
2873
|
}
|
|
@@ -3024,7 +2896,7 @@ var CACHE_FILE2 = ".rigstate/rules-cache.json";
|
|
|
3024
2896
|
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
3025
2897
|
var CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
3026
2898
|
function createCheckCommand() {
|
|
3027
|
-
return new
|
|
2899
|
+
return new import_commander9.Command("check").description("Validate code against Guardian architectural rules").argument("[path]", "Directory or file to check", ".").option("--project <id>", "Project ID (or use .rigstate manifest)").option("--strict [level]", 'Exit 1 on violations. Level: "all" (default) or "critical"').option("--staged", "Only check git staged files (for pre-commit hooks)").option("--json", "Output results as JSON").option("--no-cache", "Skip rule cache and fetch fresh from API").action(async (targetPath, options) => {
|
|
3028
2900
|
const spinner = (0, import_ora7.default)();
|
|
3029
2901
|
try {
|
|
3030
2902
|
let projectId = options.project;
|
|
@@ -3040,15 +2912,15 @@ function createCheckCommand() {
|
|
|
3040
2912
|
projectId = getProjectId();
|
|
3041
2913
|
}
|
|
3042
2914
|
if (!projectId) {
|
|
3043
|
-
console.log(
|
|
3044
|
-
console.log(
|
|
2915
|
+
console.log(import_chalk14.default.red("\u274C No project context found."));
|
|
2916
|
+
console.log(import_chalk14.default.dim(' Run "rigstate link" or pass --project <id>'));
|
|
3045
2917
|
process.exit(2);
|
|
3046
2918
|
}
|
|
3047
2919
|
let apiKey;
|
|
3048
2920
|
try {
|
|
3049
2921
|
apiKey = getApiKey();
|
|
3050
2922
|
} catch {
|
|
3051
|
-
console.log(
|
|
2923
|
+
console.log(import_chalk14.default.red('\u274C Not authenticated. Run "rigstate login" first.'));
|
|
3052
2924
|
process.exit(2);
|
|
3053
2925
|
}
|
|
3054
2926
|
spinner.start("Fetching Guardian rules...");
|
|
@@ -3076,17 +2948,17 @@ function createCheckCommand() {
|
|
|
3076
2948
|
} catch (apiError) {
|
|
3077
2949
|
const cached = await loadCachedRules(projectId);
|
|
3078
2950
|
if (cached && !isStale(cached.timestamp, CACHE_MAX_AGE_MS)) {
|
|
3079
|
-
spinner.warn(
|
|
2951
|
+
spinner.warn(import_chalk14.default.yellow("Using cached rules (API unavailable)"));
|
|
3080
2952
|
rules = cached.rules;
|
|
3081
2953
|
settings = cached.settings;
|
|
3082
2954
|
} else {
|
|
3083
|
-
spinner.fail(
|
|
3084
|
-
console.log(
|
|
2955
|
+
spinner.fail(import_chalk14.default.red("Failed to fetch rules and no valid cache"));
|
|
2956
|
+
console.log(import_chalk14.default.dim(` Error: ${apiError.message}`));
|
|
3085
2957
|
process.exit(2);
|
|
3086
2958
|
}
|
|
3087
2959
|
}
|
|
3088
2960
|
spinner.succeed(`Loaded ${rules.length} Guardian rules`);
|
|
3089
|
-
const scanPath =
|
|
2961
|
+
const scanPath = import_path13.default.resolve(process.cwd(), targetPath);
|
|
3090
2962
|
let filesToCheck;
|
|
3091
2963
|
if (options.staged) {
|
|
3092
2964
|
spinner.start("Getting staged files...");
|
|
@@ -3095,14 +2967,14 @@ function createCheckCommand() {
|
|
|
3095
2967
|
encoding: "utf-8",
|
|
3096
2968
|
cwd: process.cwd()
|
|
3097
2969
|
});
|
|
3098
|
-
filesToCheck = stagedOutput.split("\n").filter((f) => f.trim()).filter((f) => isCodeFile2(f)).map((f) =>
|
|
2970
|
+
filesToCheck = stagedOutput.split("\n").filter((f) => f.trim()).filter((f) => isCodeFile2(f)).map((f) => import_path13.default.resolve(process.cwd(), f));
|
|
3099
2971
|
} catch {
|
|
3100
2972
|
spinner.fail("Not a git repository or no staged files");
|
|
3101
2973
|
process.exit(2);
|
|
3102
2974
|
}
|
|
3103
2975
|
} else {
|
|
3104
|
-
spinner.start(`Scanning ${
|
|
3105
|
-
const pattern =
|
|
2976
|
+
spinner.start(`Scanning ${import_chalk14.default.cyan(targetPath)}...`);
|
|
2977
|
+
const pattern = import_path13.default.join(scanPath, "**/*");
|
|
3106
2978
|
const allFiles = await (0, import_glob3.glob)(pattern, {
|
|
3107
2979
|
nodir: true,
|
|
3108
2980
|
dot: false,
|
|
@@ -3118,7 +2990,7 @@ function createCheckCommand() {
|
|
|
3118
2990
|
filesToCheck = allFiles.filter((f) => isCodeFile2(f));
|
|
3119
2991
|
}
|
|
3120
2992
|
if (filesToCheck.length === 0) {
|
|
3121
|
-
spinner.warn(
|
|
2993
|
+
spinner.warn(import_chalk14.default.yellow("No code files found to check."));
|
|
3122
2994
|
outputResults([], !!options.json);
|
|
3123
2995
|
process.exit(0);
|
|
3124
2996
|
}
|
|
@@ -3127,7 +2999,7 @@ function createCheckCommand() {
|
|
|
3127
2999
|
const results = [];
|
|
3128
3000
|
for (let i = 0; i < filesToCheck.length; i++) {
|
|
3129
3001
|
const file = filesToCheck[i];
|
|
3130
|
-
spinner.text = `Checking ${i + 1}/${filesToCheck.length}: ${
|
|
3002
|
+
spinner.text = `Checking ${i + 1}/${filesToCheck.length}: ${import_path13.default.basename(file)}`;
|
|
3131
3003
|
const result = await checkFile(file, rules, process.cwd());
|
|
3132
3004
|
results.push(result);
|
|
3133
3005
|
}
|
|
@@ -3137,47 +3009,47 @@ function createCheckCommand() {
|
|
|
3137
3009
|
outputResults(results, true);
|
|
3138
3010
|
} else {
|
|
3139
3011
|
outputResults(results, false);
|
|
3140
|
-
console.log("\n" +
|
|
3141
|
-
console.log(
|
|
3142
|
-
console.log(`Files checked: ${
|
|
3143
|
-
console.log(`Total violations: ${summary.totalViolations > 0 ?
|
|
3012
|
+
console.log("\n" + import_chalk14.default.bold("\u{1F4CA} Summary"));
|
|
3013
|
+
console.log(import_chalk14.default.dim("\u2500".repeat(50)));
|
|
3014
|
+
console.log(`Files checked: ${import_chalk14.default.cyan(summary.totalFiles)}`);
|
|
3015
|
+
console.log(`Total violations: ${summary.totalViolations > 0 ? import_chalk14.default.red(summary.totalViolations) : import_chalk14.default.green(0)}`);
|
|
3144
3016
|
if (summary.totalViolations > 0) {
|
|
3145
|
-
console.log(` ${
|
|
3146
|
-
console.log(` ${
|
|
3147
|
-
console.log(` ${
|
|
3017
|
+
console.log(` ${import_chalk14.default.red("Critical:")} ${summary.criticalCount}`);
|
|
3018
|
+
console.log(` ${import_chalk14.default.yellow("Warning:")} ${summary.warningCount}`);
|
|
3019
|
+
console.log(` ${import_chalk14.default.blue("Info:")} ${summary.infoCount}`);
|
|
3148
3020
|
}
|
|
3149
|
-
console.log(
|
|
3021
|
+
console.log(import_chalk14.default.dim("\u2500".repeat(50)));
|
|
3150
3022
|
}
|
|
3151
3023
|
if (options.strict !== void 0) {
|
|
3152
3024
|
const strictLevel = typeof options.strict === "string" ? options.strict : "all";
|
|
3153
3025
|
if (strictLevel === "critical" && summary.criticalCount > 0) {
|
|
3154
|
-
console.log(
|
|
3026
|
+
console.log(import_chalk14.default.red("\n\u274C Check failed: Critical violations found"));
|
|
3155
3027
|
process.exit(1);
|
|
3156
3028
|
} else if (strictLevel === "all" && summary.totalViolations > 0) {
|
|
3157
|
-
console.log(
|
|
3029
|
+
console.log(import_chalk14.default.red("\n\u274C Check failed: Violations found"));
|
|
3158
3030
|
process.exit(1);
|
|
3159
3031
|
}
|
|
3160
3032
|
}
|
|
3161
3033
|
if (summary.totalViolations === 0) {
|
|
3162
|
-
console.log(
|
|
3034
|
+
console.log(import_chalk14.default.green("\n\u2705 All checks passed!"));
|
|
3163
3035
|
}
|
|
3164
3036
|
process.exit(0);
|
|
3165
3037
|
} catch (error) {
|
|
3166
|
-
spinner.fail(
|
|
3167
|
-
console.error(
|
|
3038
|
+
spinner.fail(import_chalk14.default.red("Check failed"));
|
|
3039
|
+
console.error(import_chalk14.default.red("Error:"), error.message);
|
|
3168
3040
|
process.exit(2);
|
|
3169
3041
|
}
|
|
3170
3042
|
});
|
|
3171
3043
|
}
|
|
3172
3044
|
function isCodeFile2(filePath) {
|
|
3173
3045
|
const codeExtensions = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
3174
|
-
const ext =
|
|
3046
|
+
const ext = import_path13.default.extname(filePath).toLowerCase();
|
|
3175
3047
|
return codeExtensions.includes(ext);
|
|
3176
3048
|
}
|
|
3177
3049
|
async function loadCachedRules(projectId) {
|
|
3178
3050
|
try {
|
|
3179
|
-
const cachePath =
|
|
3180
|
-
const content = await
|
|
3051
|
+
const cachePath = import_path13.default.join(process.cwd(), CACHE_FILE2);
|
|
3052
|
+
const content = await import_promises13.default.readFile(cachePath, "utf-8");
|
|
3181
3053
|
const cached = JSON.parse(content);
|
|
3182
3054
|
if (cached.projectId !== projectId) {
|
|
3183
3055
|
return null;
|
|
@@ -3189,16 +3061,16 @@ async function loadCachedRules(projectId) {
|
|
|
3189
3061
|
}
|
|
3190
3062
|
async function saveCachedRules(projectId, rules, settings) {
|
|
3191
3063
|
try {
|
|
3192
|
-
const cacheDir =
|
|
3193
|
-
await
|
|
3064
|
+
const cacheDir = import_path13.default.join(process.cwd(), ".rigstate");
|
|
3065
|
+
await import_promises13.default.mkdir(cacheDir, { recursive: true });
|
|
3194
3066
|
const cached = {
|
|
3195
3067
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3196
3068
|
projectId,
|
|
3197
3069
|
rules,
|
|
3198
3070
|
settings
|
|
3199
3071
|
};
|
|
3200
|
-
await
|
|
3201
|
-
|
|
3072
|
+
await import_promises13.default.writeFile(
|
|
3073
|
+
import_path13.default.join(cacheDir, "rules-cache.json"),
|
|
3202
3074
|
JSON.stringify(cached, null, 2)
|
|
3203
3075
|
);
|
|
3204
3076
|
} catch {
|
|
@@ -3220,8 +3092,8 @@ function outputResults(results, json) {
|
|
|
3220
3092
|
if (!hasViolations) {
|
|
3221
3093
|
return;
|
|
3222
3094
|
}
|
|
3223
|
-
console.log("\n" +
|
|
3224
|
-
console.log(
|
|
3095
|
+
console.log("\n" + import_chalk14.default.bold("\u{1F50D} Violations Found"));
|
|
3096
|
+
console.log(import_chalk14.default.dim("\u2500".repeat(50)));
|
|
3225
3097
|
for (const result of results) {
|
|
3226
3098
|
if (result.violations.length > 0) {
|
|
3227
3099
|
formatViolations(result.violations);
|
|
@@ -3229,8 +3101,125 @@ function outputResults(results, json) {
|
|
|
3229
3101
|
}
|
|
3230
3102
|
}
|
|
3231
3103
|
|
|
3232
|
-
// src/
|
|
3233
|
-
|
|
3104
|
+
// src/commands/hooks.ts
|
|
3105
|
+
init_cjs_shims();
|
|
3106
|
+
var import_commander10 = require("commander");
|
|
3107
|
+
var import_chalk15 = __toESM(require("chalk"), 1);
|
|
3108
|
+
var import_promises14 = __toESM(require("fs/promises"), 1);
|
|
3109
|
+
var import_path14 = __toESM(require("path"), 1);
|
|
3110
|
+
var PRE_COMMIT_SCRIPT = `#!/bin/sh
|
|
3111
|
+
# Rigstate Guardian Pre-commit Hook
|
|
3112
|
+
# Installed by: rigstate hooks install
|
|
3113
|
+
|
|
3114
|
+
# 1. Silent Sentinel Check (Phase 5)
|
|
3115
|
+
if [ -f .rigstate/guardian.lock ]; then
|
|
3116
|
+
echo "\u{1F6D1} INTERVENTION ACTIVE: Commit blocked by Silent Sentinel."
|
|
3117
|
+
echo " A critical violation ('HARD_LOCK') was detected by the Guardian Daemon."
|
|
3118
|
+
echo " Please fix the violation to unlock the repo."
|
|
3119
|
+
echo ""
|
|
3120
|
+
if grep -q "HARD_LOCK_ACTIVE" .rigstate/guardian.lock; then
|
|
3121
|
+
cat .rigstate/guardian.lock
|
|
3122
|
+
fi
|
|
3123
|
+
exit 1
|
|
3124
|
+
fi
|
|
3125
|
+
|
|
3126
|
+
echo "\u{1F6E1}\uFE0F Running Guardian checks..."
|
|
3127
|
+
|
|
3128
|
+
# Run check with strict mode for critical violations
|
|
3129
|
+
rigstate check --staged --strict=critical
|
|
3130
|
+
|
|
3131
|
+
# Exit with the same code as rigstate check
|
|
3132
|
+
exit $?
|
|
3133
|
+
`;
|
|
3134
|
+
function createHooksCommand() {
|
|
3135
|
+
const hooks = new import_commander10.Command("hooks").description("Manage git hooks for Guardian integration");
|
|
3136
|
+
hooks.command("install").description("Install pre-commit hook to run Guardian checks").option("--strict [level]", 'Strict level: "all" or "critical" (default)', "critical").action(async (options) => {
|
|
3137
|
+
try {
|
|
3138
|
+
const gitDir = import_path14.default.join(process.cwd(), ".git");
|
|
3139
|
+
try {
|
|
3140
|
+
await import_promises14.default.access(gitDir);
|
|
3141
|
+
} catch {
|
|
3142
|
+
console.log(import_chalk15.default.red("\u274C Not a git repository."));
|
|
3143
|
+
console.log(import_chalk15.default.dim(' Initialize with "git init" first.'));
|
|
3144
|
+
process.exit(1);
|
|
3145
|
+
}
|
|
3146
|
+
const hooksDir = import_path14.default.join(gitDir, "hooks");
|
|
3147
|
+
await import_promises14.default.mkdir(hooksDir, { recursive: true });
|
|
3148
|
+
const preCommitPath = import_path14.default.join(hooksDir, "pre-commit");
|
|
3149
|
+
let existingContent = "";
|
|
3150
|
+
try {
|
|
3151
|
+
existingContent = await import_promises14.default.readFile(preCommitPath, "utf-8");
|
|
3152
|
+
if (existingContent.includes("rigstate")) {
|
|
3153
|
+
console.log(import_chalk15.default.yellow("\u26A0 Rigstate pre-commit hook already installed."));
|
|
3154
|
+
console.log(import_chalk15.default.dim(' Use "rigstate hooks uninstall" to remove first.'));
|
|
3155
|
+
return;
|
|
3156
|
+
}
|
|
3157
|
+
} catch {
|
|
3158
|
+
}
|
|
3159
|
+
let script = PRE_COMMIT_SCRIPT;
|
|
3160
|
+
if (options.strict === "all") {
|
|
3161
|
+
script = script.replace("--strict=critical", "--strict");
|
|
3162
|
+
}
|
|
3163
|
+
if (existingContent && !existingContent.includes("rigstate")) {
|
|
3164
|
+
const combinedScript = existingContent + "\n\n" + script.replace("#!/bin/sh\n", "");
|
|
3165
|
+
await import_promises14.default.writeFile(preCommitPath, combinedScript, { mode: 493 });
|
|
3166
|
+
console.log(import_chalk15.default.green("\u2705 Rigstate hook appended to existing pre-commit."));
|
|
3167
|
+
} else {
|
|
3168
|
+
await import_promises14.default.writeFile(preCommitPath, script, { mode: 493 });
|
|
3169
|
+
console.log(import_chalk15.default.green("\u2705 Pre-commit hook installed!"));
|
|
3170
|
+
}
|
|
3171
|
+
console.log(import_chalk15.default.dim(` Path: ${preCommitPath}`));
|
|
3172
|
+
console.log(import_chalk15.default.dim(` Strict level: ${options.strict}`));
|
|
3173
|
+
console.log("");
|
|
3174
|
+
console.log(import_chalk15.default.cyan("Guardian will now check your code before each commit."));
|
|
3175
|
+
console.log(import_chalk15.default.dim('Use "rigstate hooks uninstall" to remove the hook.'));
|
|
3176
|
+
} catch (error) {
|
|
3177
|
+
console.error(import_chalk15.default.red("Failed to install hook:"), error.message);
|
|
3178
|
+
process.exit(1);
|
|
3179
|
+
}
|
|
3180
|
+
});
|
|
3181
|
+
hooks.command("uninstall").description("Remove Rigstate pre-commit hook").action(async () => {
|
|
3182
|
+
try {
|
|
3183
|
+
const preCommitPath = import_path14.default.join(process.cwd(), ".git", "hooks", "pre-commit");
|
|
3184
|
+
try {
|
|
3185
|
+
const content = await import_promises14.default.readFile(preCommitPath, "utf-8");
|
|
3186
|
+
if (!content.includes("rigstate")) {
|
|
3187
|
+
console.log(import_chalk15.default.yellow("\u26A0 No Rigstate hook found in pre-commit."));
|
|
3188
|
+
return;
|
|
3189
|
+
}
|
|
3190
|
+
if (content.includes("# Rigstate Guardian Pre-commit Hook") && content.trim().split("\n").filter((l) => l && !l.startsWith("#")).length <= 4) {
|
|
3191
|
+
await import_promises14.default.unlink(preCommitPath);
|
|
3192
|
+
console.log(import_chalk15.default.green("\u2705 Pre-commit hook removed."));
|
|
3193
|
+
} else {
|
|
3194
|
+
const lines = content.split("\n");
|
|
3195
|
+
const filteredLines = [];
|
|
3196
|
+
let inRigstateSection = false;
|
|
3197
|
+
for (const line of lines) {
|
|
3198
|
+
if (line.includes("Rigstate Guardian Pre-commit Hook")) {
|
|
3199
|
+
inRigstateSection = true;
|
|
3200
|
+
continue;
|
|
3201
|
+
}
|
|
3202
|
+
if (inRigstateSection && line.includes("exit $?")) {
|
|
3203
|
+
inRigstateSection = false;
|
|
3204
|
+
continue;
|
|
3205
|
+
}
|
|
3206
|
+
if (!inRigstateSection && !line.includes("rigstate check")) {
|
|
3207
|
+
filteredLines.push(line);
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
await import_promises14.default.writeFile(preCommitPath, filteredLines.join("\n"), { mode: 493 });
|
|
3211
|
+
console.log(import_chalk15.default.green("\u2705 Rigstate section removed from pre-commit hook."));
|
|
3212
|
+
}
|
|
3213
|
+
} catch {
|
|
3214
|
+
console.log(import_chalk15.default.yellow("\u26A0 No pre-commit hook found."));
|
|
3215
|
+
}
|
|
3216
|
+
} catch (error) {
|
|
3217
|
+
console.error(import_chalk15.default.red("Failed to uninstall hook:"), error.message);
|
|
3218
|
+
process.exit(1);
|
|
3219
|
+
}
|
|
3220
|
+
});
|
|
3221
|
+
return hooks;
|
|
3222
|
+
}
|
|
3234
3223
|
|
|
3235
3224
|
// src/commands/daemon.ts
|
|
3236
3225
|
init_cjs_shims();
|
|
@@ -4802,6 +4791,7 @@ var import_child_process6 = require("child_process");
|
|
|
4802
4791
|
var import_path22 = __toESM(require("path"), 1);
|
|
4803
4792
|
var import_fs = __toESM(require("fs"), 1);
|
|
4804
4793
|
var import_url2 = require("url");
|
|
4794
|
+
init_config();
|
|
4805
4795
|
var __filename2 = (0, import_url2.fileURLToPath)(importMetaUrl);
|
|
4806
4796
|
var __dirname = import_path22.default.dirname(__filename2);
|
|
4807
4797
|
function createMcpCommand() {
|
|
@@ -4832,11 +4822,21 @@ function createMcpCommand() {
|
|
|
4832
4822
|
process.exit(1);
|
|
4833
4823
|
}
|
|
4834
4824
|
console.log(import_chalk25.default.dim(`Starting MCP server from: ${serverPath}`));
|
|
4835
|
-
|
|
4836
|
-
|
|
4825
|
+
const env = { ...process.env };
|
|
4826
|
+
try {
|
|
4827
|
+
const apiKey = getApiKey();
|
|
4828
|
+
if (apiKey) {
|
|
4829
|
+
env.RIGSTATE_API_KEY = apiKey;
|
|
4830
|
+
env.RIGSTATE_APP_URL = getApiUrl();
|
|
4831
|
+
env.RIGSTATE_API_URL = getApiUrl();
|
|
4832
|
+
}
|
|
4833
|
+
} catch (e) {
|
|
4834
|
+
}
|
|
4835
|
+
if (env.VIBE_API_KEY && !env.RIGSTATE_API_KEY) {
|
|
4836
|
+
env.RIGSTATE_API_KEY = env.VIBE_API_KEY;
|
|
4837
4837
|
}
|
|
4838
4838
|
const worker = (0, import_child_process6.spawn)("node", [serverPath], {
|
|
4839
|
-
env
|
|
4839
|
+
env,
|
|
4840
4840
|
stdio: ["inherit", "inherit", "inherit"]
|
|
4841
4841
|
});
|
|
4842
4842
|
worker.on("error", (err) => {
|