@rigstate/cli 0.7.21 → 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/.rigstate/daemon.state.json +3 -3
- package/.rigstate/rules-cache.json +1 -1
- package/dist/index.cjs +654 -643
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +651 -640
- 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/src/daemon/core.ts +64 -45
- 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,13 +3101,130 @@ 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();
|
|
3237
3226
|
var import_commander11 = require("commander");
|
|
3238
|
-
var
|
|
3227
|
+
var import_chalk20 = __toESM(require("chalk"), 1);
|
|
3239
3228
|
var import_ora8 = __toESM(require("ora"), 1);
|
|
3240
3229
|
var import_promises17 = __toESM(require("fs/promises"), 1);
|
|
3241
3230
|
var import_path19 = __toESM(require("path"), 1);
|
|
@@ -3247,7 +3236,7 @@ init_cjs_shims();
|
|
|
3247
3236
|
|
|
3248
3237
|
// src/daemon/core.ts
|
|
3249
3238
|
init_cjs_shims();
|
|
3250
|
-
var
|
|
3239
|
+
var import_chalk19 = __toESM(require("chalk"), 1);
|
|
3251
3240
|
var fs17 = __toESM(require("fs/promises"), 1);
|
|
3252
3241
|
var import_events3 = require("events");
|
|
3253
3242
|
|
|
@@ -3810,6 +3799,64 @@ async function trackSkillUsage(apiUrl, apiKey, projectId, skillId) {
|
|
|
3810
3799
|
// src/daemon/core.ts
|
|
3811
3800
|
init_skills_provisioner();
|
|
3812
3801
|
init_sync_rules();
|
|
3802
|
+
|
|
3803
|
+
// src/utils/logger.ts
|
|
3804
|
+
init_cjs_shims();
|
|
3805
|
+
var import_chalk18 = __toESM(require("chalk"), 1);
|
|
3806
|
+
var Logger = class {
|
|
3807
|
+
static formatMessage(level, message, context) {
|
|
3808
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3809
|
+
let prefix = "";
|
|
3810
|
+
switch (level) {
|
|
3811
|
+
case "INFO" /* INFO */:
|
|
3812
|
+
prefix = import_chalk18.default.blue(`[${"INFO" /* INFO */}]`);
|
|
3813
|
+
break;
|
|
3814
|
+
case "WARN" /* WARN */:
|
|
3815
|
+
prefix = import_chalk18.default.yellow(`[${"WARN" /* WARN */}]`);
|
|
3816
|
+
break;
|
|
3817
|
+
case "ERROR" /* ERROR */:
|
|
3818
|
+
prefix = import_chalk18.default.red(`[${"ERROR" /* ERROR */}]`);
|
|
3819
|
+
break;
|
|
3820
|
+
case "DEBUG" /* DEBUG */:
|
|
3821
|
+
prefix = import_chalk18.default.gray(`[${"DEBUG" /* DEBUG */}]`);
|
|
3822
|
+
break;
|
|
3823
|
+
}
|
|
3824
|
+
let output = `${import_chalk18.default.gray(timestamp)} ${prefix} ${message}`;
|
|
3825
|
+
if (context) {
|
|
3826
|
+
if (context instanceof Error) {
|
|
3827
|
+
output += `
|
|
3828
|
+
${import_chalk18.default.red(context.stack || context.message)}`;
|
|
3829
|
+
} else if (typeof context === "object") {
|
|
3830
|
+
try {
|
|
3831
|
+
output += `
|
|
3832
|
+
${import_chalk18.default.gray(JSON.stringify(context, null, 2))}`;
|
|
3833
|
+
} catch (e) {
|
|
3834
|
+
output += `
|
|
3835
|
+
${import_chalk18.default.gray("[Circular or invalid object]")}`;
|
|
3836
|
+
}
|
|
3837
|
+
} else {
|
|
3838
|
+
output += ` ${String(context)}`;
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
return output;
|
|
3842
|
+
}
|
|
3843
|
+
static info(message, context) {
|
|
3844
|
+
console.log(this.formatMessage("INFO" /* INFO */, message, context));
|
|
3845
|
+
}
|
|
3846
|
+
static warn(message, context) {
|
|
3847
|
+
console.warn(this.formatMessage("WARN" /* WARN */, message, context));
|
|
3848
|
+
}
|
|
3849
|
+
static error(message, error) {
|
|
3850
|
+
console.error(this.formatMessage("ERROR" /* ERROR */, message, error));
|
|
3851
|
+
}
|
|
3852
|
+
static debug(message, context) {
|
|
3853
|
+
if (process.env.DEBUG || process.env.RIGSTATE_DEBUG) {
|
|
3854
|
+
console.debug(this.formatMessage("DEBUG" /* DEBUG */, message, context));
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
};
|
|
3858
|
+
|
|
3859
|
+
// src/daemon/core.ts
|
|
3813
3860
|
var GuardianDaemon = class extends import_events3.EventEmitter {
|
|
3814
3861
|
config;
|
|
3815
3862
|
state;
|
|
@@ -3832,7 +3879,7 @@ var GuardianDaemon = class extends import_events3.EventEmitter {
|
|
|
3832
3879
|
}
|
|
3833
3880
|
async start() {
|
|
3834
3881
|
if (this.state.isRunning) {
|
|
3835
|
-
console.log(
|
|
3882
|
+
console.log(import_chalk19.default.yellow("Daemon is already running."));
|
|
3836
3883
|
return;
|
|
3837
3884
|
}
|
|
3838
3885
|
this.printWelcome();
|
|
@@ -3842,8 +3889,8 @@ var GuardianDaemon = class extends import_events3.EventEmitter {
|
|
|
3842
3889
|
this.interventionProtocol = createInterventionProtocol();
|
|
3843
3890
|
this.guardianMonitor = createGuardianMonitor(this.config.projectId, this.config.apiUrl, this.config.apiKey);
|
|
3844
3891
|
await this.guardianMonitor.loadRules();
|
|
3845
|
-
|
|
3846
|
-
|
|
3892
|
+
Logger.info(`Loaded ${this.guardianMonitor.getRuleCount()} rules`);
|
|
3893
|
+
Logger.info("Syncing Brain to IDE (.cursor/rules)...");
|
|
3847
3894
|
await syncProjectRules(this.config.projectId, this.config.apiKey, this.config.apiUrl);
|
|
3848
3895
|
await this.syncHeuristics();
|
|
3849
3896
|
if (this.config.checkOnChange) {
|
|
@@ -3853,100 +3900,109 @@ var GuardianDaemon = class extends import_events3.EventEmitter {
|
|
|
3853
3900
|
try {
|
|
3854
3901
|
await this.setupBridge();
|
|
3855
3902
|
} catch (e) {
|
|
3856
|
-
console.error(
|
|
3857
|
-
console.log(
|
|
3903
|
+
console.error(import_chalk19.default.yellow(` \u26A0\uFE0F Agent Bridge connection failed: ${e.message}`));
|
|
3904
|
+
console.log(import_chalk19.default.dim(" (Daemon will continue with local monitoring only)"));
|
|
3858
3905
|
}
|
|
3859
3906
|
}
|
|
3860
3907
|
this.printActive();
|
|
3861
3908
|
this.emit("started", this.state);
|
|
3862
3909
|
}
|
|
3863
3910
|
printWelcome() {
|
|
3864
|
-
console.log(
|
|
3865
|
-
console.log(
|
|
3866
|
-
console.log(
|
|
3867
|
-
console.log(
|
|
3868
|
-
console.log(
|
|
3911
|
+
console.log(import_chalk19.default.bold.blue("\n\u{1F6E1}\uFE0F Guardian Daemon Starting..."));
|
|
3912
|
+
console.log(import_chalk19.default.dim(`Project: ${this.config.projectId}`));
|
|
3913
|
+
console.log(import_chalk19.default.dim(`API URL: ${this.config.apiUrl}`));
|
|
3914
|
+
console.log(import_chalk19.default.dim(`Watch Path: ${this.config.watchPath}`));
|
|
3915
|
+
console.log(import_chalk19.default.dim("\u2500".repeat(50)));
|
|
3869
3916
|
}
|
|
3870
3917
|
printActive() {
|
|
3871
|
-
console.log(
|
|
3872
|
-
console.log(
|
|
3873
|
-
console.log(
|
|
3918
|
+
console.log(import_chalk19.default.dim("\u2500".repeat(50)));
|
|
3919
|
+
console.log(import_chalk19.default.green.bold("\u2705 Guardian Daemon is now active"));
|
|
3920
|
+
console.log(import_chalk19.default.dim("Press Ctrl+C to stop\n"));
|
|
3874
3921
|
}
|
|
3875
3922
|
async syncHeuristics() {
|
|
3876
3923
|
if (!this.heuristicEngine) return;
|
|
3877
3924
|
const synced = await this.heuristicEngine.refreshRules(this.config.projectId, this.config.apiUrl, this.config.apiKey);
|
|
3878
|
-
if (synced)
|
|
3925
|
+
if (synced) Logger.info("Synced heuristic rules");
|
|
3879
3926
|
}
|
|
3880
3927
|
setupFileWatcher() {
|
|
3881
|
-
|
|
3928
|
+
Logger.info("Starting file watcher...");
|
|
3882
3929
|
this.fileWatcher = createFileWatcher(this.config.watchPath);
|
|
3883
3930
|
this.fileWatcher.on("change", (path24) => this.handleFileChange(path24));
|
|
3884
3931
|
this.fileWatcher.start();
|
|
3885
|
-
|
|
3932
|
+
Logger.info("File watcher active");
|
|
3886
3933
|
}
|
|
3887
3934
|
async handleFileChange(filePath) {
|
|
3888
3935
|
this.state.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
3889
|
-
if (this.config.verbose)
|
|
3890
|
-
|
|
3936
|
+
if (this.config.verbose) Logger.debug(`File changed: ${filePath}`);
|
|
3937
|
+
const lineCount = await this.getLineCount(filePath);
|
|
3938
|
+
await this.runPredictiveAnalysis(filePath, lineCount);
|
|
3939
|
+
await this.runIntegrityCheck(filePath);
|
|
3940
|
+
}
|
|
3941
|
+
async getLineCount(filePath) {
|
|
3891
3942
|
try {
|
|
3892
3943
|
const content = await fs17.readFile(filePath, "utf-8");
|
|
3893
|
-
|
|
3944
|
+
return content.split("\n").length;
|
|
3894
3945
|
} catch (e) {
|
|
3946
|
+
return 0;
|
|
3895
3947
|
}
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3948
|
+
}
|
|
3949
|
+
async runPredictiveAnalysis(filePath, lineCount) {
|
|
3950
|
+
if (!this.heuristicEngine || !this.interventionProtocol || !this.guardianMonitor) return;
|
|
3951
|
+
const matches = await this.heuristicEngine.analyzeFile(filePath, {
|
|
3952
|
+
lineCount,
|
|
3953
|
+
rules: this.guardianMonitor.getRules()
|
|
3954
|
+
});
|
|
3955
|
+
for (const match of matches) {
|
|
3956
|
+
Logger.info(`PREDICTIVE ACTIVATION: ${match.skillId} (${match.reason})`);
|
|
3957
|
+
const decision = this.interventionProtocol.evaluateTrigger(match.skillId, match.confidence);
|
|
3958
|
+
this.interventionProtocol.enforce(decision);
|
|
3959
|
+
await jitProvisionSkill(match.skillId, this.config.apiUrl, this.config.apiKey, this.config.projectId, process.cwd());
|
|
3960
|
+
await trackSkillUsage(this.config.apiUrl, this.config.apiKey, this.config.projectId, match.skillId);
|
|
3961
|
+
this.emit("skill:suggestion", match);
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
async runIntegrityCheck(filePath) {
|
|
3965
|
+
if (!this.guardianMonitor) return;
|
|
3966
|
+
if (this.interventionProtocol) this.interventionProtocol.clear(filePath);
|
|
3967
|
+
const result = await this.guardianMonitor.checkFile(filePath);
|
|
3968
|
+
this.state.filesChecked++;
|
|
3969
|
+
if (result.violations.length > 0) {
|
|
3970
|
+
this.handleViolations(filePath, result.violations);
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
handleViolations(filePath, violations) {
|
|
3974
|
+
this.state.violationsFound += violations.length;
|
|
3975
|
+
this.emit("violation", { file: filePath, violations });
|
|
3976
|
+
for (const v of violations) {
|
|
3977
|
+
const level = v.severity === "critical" ? "error" : v.severity === "warning" ? "warn" : "info";
|
|
3978
|
+
Logger[level](`[${v.severity.toUpperCase()}] ${filePath}: ${v.message}`);
|
|
3979
|
+
if (this.interventionProtocol) {
|
|
3980
|
+
const decision = this.interventionProtocol.evaluateViolation(v.message, v.severity);
|
|
3905
3981
|
this.interventionProtocol.enforce(decision);
|
|
3906
|
-
|
|
3907
|
-
await trackSkillUsage(this.config.apiUrl, this.config.apiKey, this.config.projectId, match.skillId);
|
|
3908
|
-
this.emit("skill:suggestion", match);
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
if (this.guardianMonitor) {
|
|
3912
|
-
if (this.interventionProtocol) this.interventionProtocol.clear(filePath);
|
|
3913
|
-
const result = await this.guardianMonitor.checkFile(filePath);
|
|
3914
|
-
this.state.filesChecked++;
|
|
3915
|
-
if (result.violations.length > 0) {
|
|
3916
|
-
this.state.violationsFound += result.violations.length;
|
|
3917
|
-
this.emit("violation", { file: filePath, violations: result.violations });
|
|
3918
|
-
for (const v of result.violations) {
|
|
3919
|
-
const color = v.severity === "critical" ? import_chalk18.default.red : v.severity === "warning" ? import_chalk18.default.yellow : import_chalk18.default.blue;
|
|
3920
|
-
console.log(color(` [${v.severity.toUpperCase()}] ${filePath}: ${v.message}`));
|
|
3921
|
-
if (this.interventionProtocol) {
|
|
3922
|
-
const decision = this.interventionProtocol.evaluateViolation(v.message, v.severity);
|
|
3923
|
-
this.interventionProtocol.enforce(decision);
|
|
3924
|
-
this.interventionProtocol.registerViolation(filePath, decision);
|
|
3925
|
-
}
|
|
3926
|
-
}
|
|
3982
|
+
this.interventionProtocol.registerViolation(filePath, decision);
|
|
3927
3983
|
}
|
|
3928
3984
|
}
|
|
3929
3985
|
}
|
|
3930
3986
|
async setupBridge() {
|
|
3931
|
-
console.log(
|
|
3987
|
+
console.log(import_chalk19.default.dim("\u{1F309} Connecting to Agent Bridge..."));
|
|
3932
3988
|
this.bridgeListener = createBridgeListener(this.config.projectId, this.config.apiUrl, this.config.apiKey);
|
|
3933
3989
|
this.bridgeListener.on("task", (task) => {
|
|
3934
3990
|
this.state.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
|
|
3935
3991
|
this.state.tasksProcessed++;
|
|
3936
|
-
console.log(
|
|
3992
|
+
console.log(import_chalk19.default.cyan(`
|
|
3937
3993
|
\u{1F4E5} New task received: ${task.id}`));
|
|
3938
3994
|
this.emit("task", task);
|
|
3939
3995
|
});
|
|
3940
3996
|
await this.bridgeListener.connect();
|
|
3941
|
-
console.log(
|
|
3997
|
+
console.log(import_chalk19.default.green(" \u2713 Agent Bridge connected"));
|
|
3942
3998
|
}
|
|
3943
3999
|
async stop() {
|
|
3944
4000
|
if (!this.state.isRunning) return;
|
|
3945
|
-
console.log(
|
|
4001
|
+
console.log(import_chalk19.default.dim("\n\u{1F6D1} Stopping Guardian Daemon..."));
|
|
3946
4002
|
if (this.fileWatcher) await this.fileWatcher.stop();
|
|
3947
4003
|
if (this.bridgeListener) await this.bridgeListener.disconnect();
|
|
3948
4004
|
this.state.isRunning = false;
|
|
3949
|
-
console.log(
|
|
4005
|
+
console.log(import_chalk19.default.green("\u2713 Daemon stopped."));
|
|
3950
4006
|
this.emit("stopped", this.state);
|
|
3951
4007
|
}
|
|
3952
4008
|
getState() {
|
|
@@ -4009,8 +4065,8 @@ function createDaemonCommand() {
|
|
|
4009
4065
|
const pid = parseInt(content.trim(), 10);
|
|
4010
4066
|
try {
|
|
4011
4067
|
process.kill(pid, 0);
|
|
4012
|
-
console.log(
|
|
4013
|
-
console.log(
|
|
4068
|
+
console.log(import_chalk20.default.yellow("\u26A0 Another daemon instance is active (PID " + pid + ")."));
|
|
4069
|
+
console.log(import_chalk20.default.dim(` Run "rigstate daemon status" for details or Ctrl+C to stop.
|
|
4014
4070
|
`));
|
|
4015
4071
|
} catch {
|
|
4016
4072
|
await import_promises17.default.unlink(pidPath).catch(() => {
|
|
@@ -4028,7 +4084,7 @@ function createDaemonCommand() {
|
|
|
4028
4084
|
spinner.stop();
|
|
4029
4085
|
await writePidFile();
|
|
4030
4086
|
process.on("SIGINT", async () => {
|
|
4031
|
-
console.log(
|
|
4087
|
+
console.log(import_chalk20.default.dim("\n\nShutting down..."));
|
|
4032
4088
|
await daemonInstance.stop();
|
|
4033
4089
|
await cleanupPidFile();
|
|
4034
4090
|
process.exit(0);
|
|
@@ -4048,8 +4104,8 @@ function createDaemonCommand() {
|
|
|
4048
4104
|
await new Promise(() => {
|
|
4049
4105
|
});
|
|
4050
4106
|
} catch (error) {
|
|
4051
|
-
spinner.fail(
|
|
4052
|
-
console.error(
|
|
4107
|
+
spinner.fail(import_chalk20.default.red("Failed to start daemon"));
|
|
4108
|
+
console.error(import_chalk20.default.red("Error:"), error.message);
|
|
4053
4109
|
process.exit(1);
|
|
4054
4110
|
}
|
|
4055
4111
|
});
|
|
@@ -4098,46 +4154,46 @@ async function writeStateFile(state) {
|
|
|
4098
4154
|
}
|
|
4099
4155
|
}
|
|
4100
4156
|
async function showStatus() {
|
|
4101
|
-
console.log(
|
|
4157
|
+
console.log(import_chalk20.default.bold("\n\u{1F6E1}\uFE0F Guardian Daemon Status\n"));
|
|
4102
4158
|
const running = await isRunning();
|
|
4103
4159
|
if (!running) {
|
|
4104
|
-
console.log(
|
|
4105
|
-
console.log(
|
|
4160
|
+
console.log(import_chalk20.default.yellow("Status: Not running"));
|
|
4161
|
+
console.log(import_chalk20.default.dim('Use "rigstate daemon" to start.\n'));
|
|
4106
4162
|
return;
|
|
4107
4163
|
}
|
|
4108
|
-
console.log(
|
|
4164
|
+
console.log(import_chalk20.default.green("Status: Running"));
|
|
4109
4165
|
try {
|
|
4110
4166
|
const statePath = import_path19.default.join(process.cwd(), STATE_FILE);
|
|
4111
4167
|
const content = await import_promises17.default.readFile(statePath, "utf-8");
|
|
4112
4168
|
const state = JSON.parse(content);
|
|
4113
|
-
console.log(
|
|
4169
|
+
console.log(import_chalk20.default.dim("\u2500".repeat(40)));
|
|
4114
4170
|
console.log(`Started at: ${state.startedAt || "Unknown"}`);
|
|
4115
4171
|
console.log(`Files checked: ${state.filesChecked || 0}`);
|
|
4116
4172
|
console.log(`Violations: ${state.violationsFound || 0}`);
|
|
4117
4173
|
console.log(`Tasks processed: ${state.tasksProcessed || 0}`);
|
|
4118
4174
|
console.log(`Last activity: ${state.lastActivity || "None"}`);
|
|
4119
|
-
console.log(
|
|
4175
|
+
console.log(import_chalk20.default.dim("\u2500".repeat(40)));
|
|
4120
4176
|
} catch {
|
|
4121
|
-
console.log(
|
|
4177
|
+
console.log(import_chalk20.default.dim("(State file not found)"));
|
|
4122
4178
|
}
|
|
4123
4179
|
try {
|
|
4124
4180
|
const pidPath = import_path19.default.join(process.cwd(), PID_FILE);
|
|
4125
4181
|
const pid = await import_promises17.default.readFile(pidPath, "utf-8");
|
|
4126
|
-
console.log(
|
|
4182
|
+
console.log(import_chalk20.default.dim(`PID: ${pid.trim()}`));
|
|
4127
4183
|
} catch {
|
|
4128
4184
|
}
|
|
4129
4185
|
console.log("");
|
|
4130
4186
|
}
|
|
4131
4187
|
async function enableDaemon() {
|
|
4132
|
-
console.log(
|
|
4188
|
+
console.log(import_chalk20.default.bold("\n\u2699\uFE0F Enabling Rigstate Background Service (macOS)\n"));
|
|
4133
4189
|
if (process.platform !== "darwin") {
|
|
4134
|
-
console.error(
|
|
4135
|
-
console.error(
|
|
4190
|
+
console.error(import_chalk20.default.red("\u274C Currently only macOS is supported for auto-start."));
|
|
4191
|
+
console.error(import_chalk20.default.yellow("PRs welcome for Linux/Windows support!"));
|
|
4136
4192
|
return;
|
|
4137
4193
|
}
|
|
4138
4194
|
const homeDir = process.env.HOME || "";
|
|
4139
4195
|
if (!homeDir) {
|
|
4140
|
-
console.error(
|
|
4196
|
+
console.error(import_chalk20.default.red("\u274C Could not determine HOME directory."));
|
|
4141
4197
|
return;
|
|
4142
4198
|
}
|
|
4143
4199
|
const agentsDir = import_path19.default.join(homeDir, "Library/LaunchAgents");
|
|
@@ -4179,32 +4235,32 @@ async function enableDaemon() {
|
|
|
4179
4235
|
</plist>`;
|
|
4180
4236
|
try {
|
|
4181
4237
|
await import_promises17.default.writeFile(plistPath, plistContent);
|
|
4182
|
-
console.log(
|
|
4238
|
+
console.log(import_chalk20.default.dim(`Created plist at: ${plistPath}`));
|
|
4183
4239
|
try {
|
|
4184
4240
|
await execShellCommand(`launchctl unload ${plistPath}`);
|
|
4185
4241
|
} catch (e) {
|
|
4186
4242
|
}
|
|
4187
4243
|
await execShellCommand(`launchctl load ${plistPath}`);
|
|
4188
|
-
console.log(
|
|
4189
|
-
console.log(
|
|
4190
|
-
console.log(
|
|
4244
|
+
console.log(import_chalk20.default.green("\u2705 Successfully enabled background daemon!"));
|
|
4245
|
+
console.log(import_chalk20.default.dim(`Logs: ${logDir}`));
|
|
4246
|
+
console.log(import_chalk20.default.dim("The daemon will now restart automatically if it crashes or on reboot."));
|
|
4191
4247
|
} catch (error) {
|
|
4192
|
-
console.error(
|
|
4248
|
+
console.error(import_chalk20.default.red("\u274C Failed to enable daemon:"), error.message);
|
|
4193
4249
|
}
|
|
4194
4250
|
}
|
|
4195
4251
|
async function disableDaemon() {
|
|
4196
|
-
console.log(
|
|
4252
|
+
console.log(import_chalk20.default.bold("\n\u2699\uFE0F Disabling Rigstate Background Service\n"));
|
|
4197
4253
|
const homeDir = process.env.HOME || "";
|
|
4198
4254
|
const plistPath = import_path19.default.join(homeDir, "Library/LaunchAgents/com.rigstate.daemon.plist");
|
|
4199
4255
|
try {
|
|
4200
4256
|
await execShellCommand(`launchctl unload ${plistPath}`);
|
|
4201
4257
|
await import_promises17.default.unlink(plistPath);
|
|
4202
|
-
console.log(
|
|
4258
|
+
console.log(import_chalk20.default.green("\u2705 Successfully disabled background daemon."));
|
|
4203
4259
|
} catch (error) {
|
|
4204
4260
|
if (error.code === "ENOENT") {
|
|
4205
|
-
console.log(
|
|
4261
|
+
console.log(import_chalk20.default.green("\u2705 Daemon was not enabled."));
|
|
4206
4262
|
} else {
|
|
4207
|
-
console.error(
|
|
4263
|
+
console.error(import_chalk20.default.red("\u274C Failed to disable daemon:"), error.message);
|
|
4208
4264
|
}
|
|
4209
4265
|
}
|
|
4210
4266
|
}
|
|
@@ -4220,7 +4276,7 @@ async function execShellCommand(cmd) {
|
|
|
4220
4276
|
// src/commands/work.ts
|
|
4221
4277
|
init_cjs_shims();
|
|
4222
4278
|
var import_commander12 = require("commander");
|
|
4223
|
-
var
|
|
4279
|
+
var import_chalk21 = __toESM(require("chalk"), 1);
|
|
4224
4280
|
var import_ora9 = __toESM(require("ora"), 1);
|
|
4225
4281
|
var import_axios15 = __toESM(require("axios"), 1);
|
|
4226
4282
|
var import_inquirer2 = __toESM(require("inquirer"), 1);
|
|
@@ -4257,7 +4313,7 @@ async function listInteractive() {
|
|
|
4257
4313
|
});
|
|
4258
4314
|
spinner.stop();
|
|
4259
4315
|
if (actionableTasks.length === 0) {
|
|
4260
|
-
console.log(
|
|
4316
|
+
console.log(import_chalk21.default.yellow("Roadmap clear. No actionable tasks found."));
|
|
4261
4317
|
return;
|
|
4262
4318
|
}
|
|
4263
4319
|
const choices = actionableTasks.map((t) => {
|
|
@@ -4266,7 +4322,7 @@ async function listInteractive() {
|
|
|
4266
4322
|
if (t.status === "IN_PROGRESS") icon = "\u{1F525}";
|
|
4267
4323
|
if (t.status === "ACTIVE") icon = "\u25B6\uFE0F";
|
|
4268
4324
|
return {
|
|
4269
|
-
name: `${icon} ${
|
|
4325
|
+
name: `${icon} ${import_chalk21.default.bold(id)}: ${t.title} [${t.status}]`,
|
|
4270
4326
|
value: t.id
|
|
4271
4327
|
};
|
|
4272
4328
|
});
|
|
@@ -4309,25 +4365,25 @@ async function setTaskStatus(taskId, status) {
|
|
|
4309
4365
|
{ step_id: realId, status, project_id: projectId },
|
|
4310
4366
|
{ headers: { "Authorization": `Bearer ${apiKey}` } }
|
|
4311
4367
|
);
|
|
4312
|
-
spinner.succeed(
|
|
4368
|
+
spinner.succeed(import_chalk21.default.green(`Task updated to ${status}.`));
|
|
4313
4369
|
if (status === "IN_PROGRESS") {
|
|
4314
|
-
console.log(
|
|
4370
|
+
console.log(import_chalk21.default.blue(`
|
|
4315
4371
|
\u{1F4A1} Tip: Provide 'Frank' with context by mentioning @.cursorrules in your chat.`));
|
|
4316
4372
|
}
|
|
4317
4373
|
} catch (e) {
|
|
4318
|
-
spinner.fail(
|
|
4374
|
+
spinner.fail(import_chalk21.default.red(`Failed: ${e.message}`));
|
|
4319
4375
|
}
|
|
4320
4376
|
}
|
|
4321
4377
|
async function finishTask(taskId) {
|
|
4322
4378
|
console.log("");
|
|
4323
|
-
console.log(
|
|
4324
|
-
console.log(
|
|
4379
|
+
console.log(import_chalk21.default.bold.yellow("\u{1F6E1}\uFE0F FRANK'S QUALITY GATE"));
|
|
4380
|
+
console.log(import_chalk21.default.dim("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
4325
4381
|
const auditSpinner = (0, import_ora9.default)(" Analyzing architectural integrity...").start();
|
|
4326
4382
|
await new Promise((r) => setTimeout(r, 1500));
|
|
4327
4383
|
auditSpinner.succeed("Architecture: VALIDATED (SEC-ARCH-01 Pass)");
|
|
4328
4384
|
await setTaskStatus(taskId, "COMPLETED");
|
|
4329
4385
|
console.log("");
|
|
4330
|
-
console.log(
|
|
4386
|
+
console.log(import_chalk21.default.bold.green("\u{1F389} TASK COMPLETE! Momentum Preserved."));
|
|
4331
4387
|
const { projectId, apiKey, apiUrl } = getContext();
|
|
4332
4388
|
await suggestNextMove(projectId, apiKey, apiUrl);
|
|
4333
4389
|
}
|
|
@@ -4344,7 +4400,7 @@ function getContext() {
|
|
|
4344
4400
|
// src/commands/watch.ts
|
|
4345
4401
|
init_cjs_shims();
|
|
4346
4402
|
var import_commander13 = require("commander");
|
|
4347
|
-
var
|
|
4403
|
+
var import_chalk22 = __toESM(require("chalk"), 1);
|
|
4348
4404
|
var import_ora10 = __toESM(require("ora"), 1);
|
|
4349
4405
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
4350
4406
|
var import_promises18 = __toESM(require("fs/promises"), 1);
|
|
@@ -4355,15 +4411,15 @@ var import_axios16 = __toESM(require("axios"), 1);
|
|
|
4355
4411
|
function createWatchCommand() {
|
|
4356
4412
|
const watch2 = new import_commander13.Command("watch");
|
|
4357
4413
|
watch2.description("Watch for changes and auto-verify roadmap tasks").option("--no-auto-commit", "Disable auto-commit on verification").option("--no-auto-push", "Disable auto-push after commit").option("--run-tests", "Run tests before committing").option("--test-command <cmd>", "Custom test command (default: npm test)").action(async (options) => {
|
|
4358
|
-
console.log(
|
|
4359
|
-
console.log(
|
|
4414
|
+
console.log(import_chalk22.default.bold.blue("\u{1F52D} Rigstate Watch Mode"));
|
|
4415
|
+
console.log(import_chalk22.default.dim("Monitoring for task completion..."));
|
|
4360
4416
|
console.log("");
|
|
4361
4417
|
let apiKey;
|
|
4362
4418
|
let projectId;
|
|
4363
4419
|
try {
|
|
4364
4420
|
apiKey = getApiKey();
|
|
4365
4421
|
} catch (e) {
|
|
4366
|
-
console.log(
|
|
4422
|
+
console.log(import_chalk22.default.red('Not authenticated. Run "rigstate login" first.'));
|
|
4367
4423
|
return;
|
|
4368
4424
|
}
|
|
4369
4425
|
projectId = getProjectId();
|
|
@@ -4377,7 +4433,7 @@ function createWatchCommand() {
|
|
|
4377
4433
|
}
|
|
4378
4434
|
}
|
|
4379
4435
|
if (!projectId) {
|
|
4380
|
-
console.log(
|
|
4436
|
+
console.log(import_chalk22.default.red('No project context. Run "rigstate link" or "rigstate sync --project <id>" first.'));
|
|
4381
4437
|
return;
|
|
4382
4438
|
}
|
|
4383
4439
|
const apiUrl = getApiUrl();
|
|
@@ -4387,8 +4443,8 @@ function createWatchCommand() {
|
|
|
4387
4443
|
runTests: options.runTests || false,
|
|
4388
4444
|
testCommand: options.testCommand || "npm test"
|
|
4389
4445
|
};
|
|
4390
|
-
console.log(
|
|
4391
|
-
console.log(
|
|
4446
|
+
console.log(import_chalk22.default.dim(`Auto-commit: ${config2.autoCommit ? "ON" : "OFF"}`));
|
|
4447
|
+
console.log(import_chalk22.default.dim(`Auto-push: ${config2.autoPush ? "ON" : "OFF"}`));
|
|
4392
4448
|
console.log("");
|
|
4393
4449
|
const fetchActiveTask = async () => {
|
|
4394
4450
|
try {
|
|
@@ -4455,7 +4511,7 @@ function createWatchCommand() {
|
|
|
4455
4511
|
}, {
|
|
4456
4512
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
4457
4513
|
});
|
|
4458
|
-
spinner.succeed(
|
|
4514
|
+
spinner.succeed(import_chalk22.default.green(`\u2705 Task #${task.step_number} completed: ${task.title}`));
|
|
4459
4515
|
if (config2.autoCommit) {
|
|
4460
4516
|
spinner.start("Committing changes...");
|
|
4461
4517
|
try {
|
|
@@ -4477,7 +4533,7 @@ function createWatchCommand() {
|
|
|
4477
4533
|
}
|
|
4478
4534
|
}
|
|
4479
4535
|
console.log("");
|
|
4480
|
-
console.log(
|
|
4536
|
+
console.log(import_chalk22.default.blue("Watching for next task..."));
|
|
4481
4537
|
} catch (e) {
|
|
4482
4538
|
spinner.fail(`Failed to complete task: ${e.message}`);
|
|
4483
4539
|
}
|
|
@@ -4490,7 +4546,7 @@ function createWatchCommand() {
|
|
|
4490
4546
|
const task = await fetchActiveTask();
|
|
4491
4547
|
if (!task) {
|
|
4492
4548
|
if (currentTask) {
|
|
4493
|
-
console.log(
|
|
4549
|
+
console.log(import_chalk22.default.green("\u{1F389} All tasks completed! Watching for new tasks..."));
|
|
4494
4550
|
currentTask = null;
|
|
4495
4551
|
}
|
|
4496
4552
|
isProcessing = false;
|
|
@@ -4499,10 +4555,10 @@ function createWatchCommand() {
|
|
|
4499
4555
|
if (!currentTask || currentTask.id !== task.id) {
|
|
4500
4556
|
currentTask = task;
|
|
4501
4557
|
console.log("");
|
|
4502
|
-
console.log(
|
|
4503
|
-
console.log(
|
|
4558
|
+
console.log(import_chalk22.default.bold.yellow(`\u{1F4CC} Active Task #${task.step_number}: ${task.title}`));
|
|
4559
|
+
console.log(import_chalk22.default.dim(`Status: ${task.status}`));
|
|
4504
4560
|
if (task.verification_criteria) {
|
|
4505
|
-
console.log(
|
|
4561
|
+
console.log(import_chalk22.default.dim("Verification: Auto-checking criteria..."));
|
|
4506
4562
|
}
|
|
4507
4563
|
}
|
|
4508
4564
|
if (task.verification_criteria && Array.isArray(task.verification_criteria)) {
|
|
@@ -4515,7 +4571,7 @@ function createWatchCommand() {
|
|
|
4515
4571
|
}
|
|
4516
4572
|
}
|
|
4517
4573
|
if (allPassed) {
|
|
4518
|
-
console.log(
|
|
4574
|
+
console.log(import_chalk22.default.green("\u2713 All verification criteria passed!"));
|
|
4519
4575
|
await completeTask(task.id, task);
|
|
4520
4576
|
currentTask = null;
|
|
4521
4577
|
}
|
|
@@ -4540,11 +4596,11 @@ function createWatchCommand() {
|
|
|
4540
4596
|
setTimeout(() => processActiveTask(), 500);
|
|
4541
4597
|
}
|
|
4542
4598
|
});
|
|
4543
|
-
console.log(
|
|
4599
|
+
console.log(import_chalk22.default.dim("Watching for file changes... (Ctrl+C to exit)"));
|
|
4544
4600
|
setInterval(() => processActiveTask(), 3e4);
|
|
4545
4601
|
process.on("SIGINT", () => {
|
|
4546
4602
|
console.log("");
|
|
4547
|
-
console.log(
|
|
4603
|
+
console.log(import_chalk22.default.dim("Watch mode stopped."));
|
|
4548
4604
|
watcher.close();
|
|
4549
4605
|
process.exit(0);
|
|
4550
4606
|
});
|
|
@@ -4555,7 +4611,7 @@ function createWatchCommand() {
|
|
|
4555
4611
|
// src/commands/focus.ts
|
|
4556
4612
|
init_cjs_shims();
|
|
4557
4613
|
var import_commander14 = require("commander");
|
|
4558
|
-
var
|
|
4614
|
+
var import_chalk23 = __toESM(require("chalk"), 1);
|
|
4559
4615
|
var import_ora11 = __toESM(require("ora"), 1);
|
|
4560
4616
|
init_config();
|
|
4561
4617
|
var import_axios17 = __toESM(require("axios"), 1);
|
|
@@ -4571,7 +4627,7 @@ function createFocusCommand() {
|
|
|
4571
4627
|
try {
|
|
4572
4628
|
apiKey = getApiKey();
|
|
4573
4629
|
} catch (e) {
|
|
4574
|
-
spinner.fail(
|
|
4630
|
+
spinner.fail(import_chalk23.default.red('Not authenticated. Run "rigstate login" first.'));
|
|
4575
4631
|
return;
|
|
4576
4632
|
}
|
|
4577
4633
|
projectId = getProjectId();
|
|
@@ -4585,7 +4641,7 @@ function createFocusCommand() {
|
|
|
4585
4641
|
}
|
|
4586
4642
|
}
|
|
4587
4643
|
if (!projectId) {
|
|
4588
|
-
spinner.fail(
|
|
4644
|
+
spinner.fail(import_chalk23.default.red('No project context. Run "rigstate link" first.'));
|
|
4589
4645
|
return;
|
|
4590
4646
|
}
|
|
4591
4647
|
const apiUrl = getApiUrl();
|
|
@@ -4616,41 +4672,41 @@ function createFocusCommand() {
|
|
|
4616
4672
|
const nextTask = activeTasks[0];
|
|
4617
4673
|
spinner.stop();
|
|
4618
4674
|
console.log("");
|
|
4619
|
-
console.log(
|
|
4620
|
-
const statusColor = nextTask.status === "IN_PROGRESS" ?
|
|
4621
|
-
console.log(
|
|
4622
|
-
console.log(
|
|
4675
|
+
console.log(import_chalk23.default.bold.blue(`\u{1F4CC} Task #${nextTask.step_number || "?"}: ${nextTask.title}`));
|
|
4676
|
+
const statusColor = nextTask.status === "IN_PROGRESS" ? import_chalk23.default.yellow : nextTask.status === "ACTIVE" ? import_chalk23.default.green : import_chalk23.default.dim;
|
|
4677
|
+
console.log(import_chalk23.default.dim("Status: ") + statusColor(nextTask.status));
|
|
4678
|
+
console.log(import_chalk23.default.dim("\u2500".repeat(60)));
|
|
4623
4679
|
if (nextTask.prompt_content) {
|
|
4624
|
-
console.log(
|
|
4625
|
-
console.log(
|
|
4680
|
+
console.log(import_chalk23.default.white(nextTask.prompt_content));
|
|
4681
|
+
console.log(import_chalk23.default.dim("\u2500".repeat(60)));
|
|
4626
4682
|
if (options.copy !== false) {
|
|
4627
4683
|
try {
|
|
4628
4684
|
if (process.platform === "darwin") {
|
|
4629
4685
|
(0, import_child_process5.execSync)("pbcopy", { input: nextTask.prompt_content });
|
|
4630
|
-
console.log(
|
|
4686
|
+
console.log(import_chalk23.default.green("\u2705 Prompt copied to clipboard! Ready to paste (Cmd+V)."));
|
|
4631
4687
|
} else if (process.platform === "linux") {
|
|
4632
4688
|
try {
|
|
4633
4689
|
(0, import_child_process5.execSync)("xclip -selection clipboard", { input: nextTask.prompt_content });
|
|
4634
|
-
console.log(
|
|
4690
|
+
console.log(import_chalk23.default.green("\u2705 Prompt copied to clipboard!"));
|
|
4635
4691
|
} catch (e) {
|
|
4636
|
-
console.log(
|
|
4692
|
+
console.log(import_chalk23.default.yellow("\u2139\uFE0F Copy prompt manually (xclip not available)"));
|
|
4637
4693
|
}
|
|
4638
4694
|
} else {
|
|
4639
|
-
console.log(
|
|
4695
|
+
console.log(import_chalk23.default.yellow("\u2139\uFE0F Copy prompt manually (Auto-copy not supported on this OS)"));
|
|
4640
4696
|
}
|
|
4641
4697
|
} catch (e) {
|
|
4642
4698
|
}
|
|
4643
4699
|
}
|
|
4644
4700
|
} else {
|
|
4645
|
-
console.log(
|
|
4701
|
+
console.log(import_chalk23.default.yellow("No prompt instructions available."));
|
|
4646
4702
|
if (nextTask.architectural_brief) {
|
|
4647
|
-
console.log(
|
|
4703
|
+
console.log(import_chalk23.default.bold("Brief:"));
|
|
4648
4704
|
console.log(nextTask.architectural_brief);
|
|
4649
4705
|
}
|
|
4650
4706
|
}
|
|
4651
4707
|
console.log("");
|
|
4652
4708
|
} catch (e) {
|
|
4653
|
-
spinner.fail(
|
|
4709
|
+
spinner.fail(import_chalk23.default.red(`Failed to fetch task: ${e.message}`));
|
|
4654
4710
|
}
|
|
4655
4711
|
});
|
|
4656
4712
|
return focus;
|
|
@@ -4662,26 +4718,26 @@ init_env();
|
|
|
4662
4718
|
// src/commands/config.ts
|
|
4663
4719
|
init_cjs_shims();
|
|
4664
4720
|
var import_commander15 = require("commander");
|
|
4665
|
-
var
|
|
4721
|
+
var import_chalk24 = __toESM(require("chalk"), 1);
|
|
4666
4722
|
init_config();
|
|
4667
4723
|
function createConfigCommand() {
|
|
4668
4724
|
const config2 = new import_commander15.Command("config");
|
|
4669
4725
|
config2.description("View or modify Rigstate configuration").argument("[key]", "Configuration key to view/set (api_key, project_id, api_url)").argument("[value]", "Value to set").action(async (key, value) => {
|
|
4670
4726
|
if (!key) {
|
|
4671
|
-
console.log(
|
|
4672
|
-
console.log(
|
|
4727
|
+
console.log(import_chalk24.default.bold("Rigstate Configuration"));
|
|
4728
|
+
console.log(import_chalk24.default.dim("\u2500".repeat(40)));
|
|
4673
4729
|
try {
|
|
4674
4730
|
const apiKey = getApiKey();
|
|
4675
|
-
console.log(`${
|
|
4731
|
+
console.log(`${import_chalk24.default.cyan("api_key")}: ${apiKey.substring(0, 20)}...`);
|
|
4676
4732
|
} catch (e) {
|
|
4677
|
-
console.log(`${
|
|
4733
|
+
console.log(`${import_chalk24.default.cyan("api_key")}: ${import_chalk24.default.dim("(not set)")}`);
|
|
4678
4734
|
}
|
|
4679
4735
|
const projectId = getProjectId();
|
|
4680
|
-
console.log(`${
|
|
4736
|
+
console.log(`${import_chalk24.default.cyan("project_id")}: ${projectId || import_chalk24.default.dim("(not set)")}`);
|
|
4681
4737
|
const apiUrl = getApiUrl();
|
|
4682
|
-
console.log(`${
|
|
4738
|
+
console.log(`${import_chalk24.default.cyan("api_url")}: ${apiUrl}`);
|
|
4683
4739
|
console.log("");
|
|
4684
|
-
console.log(
|
|
4740
|
+
console.log(import_chalk24.default.dim('Use "rigstate config <key> <value>" to set a value.'));
|
|
4685
4741
|
return;
|
|
4686
4742
|
}
|
|
4687
4743
|
if (!value) {
|
|
@@ -4691,37 +4747,37 @@ function createConfigCommand() {
|
|
|
4691
4747
|
const apiKey = getApiKey();
|
|
4692
4748
|
console.log(apiKey);
|
|
4693
4749
|
} catch (e) {
|
|
4694
|
-
console.log(
|
|
4750
|
+
console.log(import_chalk24.default.dim("(not set)"));
|
|
4695
4751
|
}
|
|
4696
4752
|
break;
|
|
4697
4753
|
case "project_id":
|
|
4698
|
-
console.log(getProjectId() ||
|
|
4754
|
+
console.log(getProjectId() || import_chalk24.default.dim("(not set)"));
|
|
4699
4755
|
break;
|
|
4700
4756
|
case "api_url":
|
|
4701
4757
|
console.log(getApiUrl());
|
|
4702
4758
|
break;
|
|
4703
4759
|
default:
|
|
4704
|
-
console.log(
|
|
4705
|
-
console.log(
|
|
4760
|
+
console.log(import_chalk24.default.red(`Unknown config key: ${key}`));
|
|
4761
|
+
console.log(import_chalk24.default.dim("Valid keys: api_key, project_id, api_url"));
|
|
4706
4762
|
}
|
|
4707
4763
|
return;
|
|
4708
4764
|
}
|
|
4709
4765
|
switch (key) {
|
|
4710
4766
|
case "api_key":
|
|
4711
4767
|
setApiKey(value);
|
|
4712
|
-
console.log(
|
|
4768
|
+
console.log(import_chalk24.default.green(`\u2705 api_key updated`));
|
|
4713
4769
|
break;
|
|
4714
4770
|
case "project_id":
|
|
4715
4771
|
setProjectId(value);
|
|
4716
|
-
console.log(
|
|
4772
|
+
console.log(import_chalk24.default.green(`\u2705 project_id updated`));
|
|
4717
4773
|
break;
|
|
4718
4774
|
case "api_url":
|
|
4719
4775
|
setApiUrl(value);
|
|
4720
|
-
console.log(
|
|
4776
|
+
console.log(import_chalk24.default.green(`\u2705 api_url updated`));
|
|
4721
4777
|
break;
|
|
4722
4778
|
default:
|
|
4723
|
-
console.log(
|
|
4724
|
-
console.log(
|
|
4779
|
+
console.log(import_chalk24.default.red(`Unknown config key: ${key}`));
|
|
4780
|
+
console.log(import_chalk24.default.dim("Valid keys: api_key, project_id, api_url"));
|
|
4725
4781
|
}
|
|
4726
4782
|
});
|
|
4727
4783
|
return config2;
|
|
@@ -4730,11 +4786,12 @@ function createConfigCommand() {
|
|
|
4730
4786
|
// src/commands/mcp.ts
|
|
4731
4787
|
init_cjs_shims();
|
|
4732
4788
|
var import_commander16 = require("commander");
|
|
4733
|
-
var
|
|
4789
|
+
var import_chalk25 = __toESM(require("chalk"), 1);
|
|
4734
4790
|
var import_child_process6 = require("child_process");
|
|
4735
4791
|
var import_path22 = __toESM(require("path"), 1);
|
|
4736
4792
|
var import_fs = __toESM(require("fs"), 1);
|
|
4737
4793
|
var import_url2 = require("url");
|
|
4794
|
+
init_config();
|
|
4738
4795
|
var __filename2 = (0, import_url2.fileURLToPath)(importMetaUrl);
|
|
4739
4796
|
var __dirname = import_path22.default.dirname(__filename2);
|
|
4740
4797
|
function createMcpCommand() {
|
|
@@ -4756,24 +4813,34 @@ function createMcpCommand() {
|
|
|
4756
4813
|
}
|
|
4757
4814
|
}
|
|
4758
4815
|
if (!serverPath) {
|
|
4759
|
-
console.error(
|
|
4760
|
-
console.error(
|
|
4761
|
-
console.error(
|
|
4816
|
+
console.error(import_chalk25.default.red("\u274C Error: Rigstate MCP Server binary not found."));
|
|
4817
|
+
console.error(import_chalk25.default.yellow("Please ensure that the mcp package is built:"));
|
|
4818
|
+
console.error(import_chalk25.default.white(" cd packages/mcp && npm run build"));
|
|
4762
4819
|
console.error("");
|
|
4763
|
-
console.error(
|
|
4764
|
-
console.error(
|
|
4820
|
+
console.error(import_chalk25.default.dim("Or run directly with:"));
|
|
4821
|
+
console.error(import_chalk25.default.white(" npx @rigstate/mcp"));
|
|
4765
4822
|
process.exit(1);
|
|
4766
4823
|
}
|
|
4767
|
-
console.log(
|
|
4768
|
-
|
|
4769
|
-
|
|
4824
|
+
console.log(import_chalk25.default.dim(`Starting MCP server from: ${serverPath}`));
|
|
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;
|
|
4770
4837
|
}
|
|
4771
4838
|
const worker = (0, import_child_process6.spawn)("node", [serverPath], {
|
|
4772
|
-
env
|
|
4839
|
+
env,
|
|
4773
4840
|
stdio: ["inherit", "inherit", "inherit"]
|
|
4774
4841
|
});
|
|
4775
4842
|
worker.on("error", (err) => {
|
|
4776
|
-
console.error(
|
|
4843
|
+
console.error(import_chalk25.default.red(`\u274C Failed to start MCP server: ${err.message}`));
|
|
4777
4844
|
process.exit(1);
|
|
4778
4845
|
});
|
|
4779
4846
|
worker.on("exit", (code) => {
|
|
@@ -4856,7 +4923,7 @@ var HiveScrubber = class {
|
|
|
4856
4923
|
};
|
|
4857
4924
|
|
|
4858
4925
|
// src/hive/gateway.ts
|
|
4859
|
-
var
|
|
4926
|
+
var import_chalk26 = __toESM(require("chalk"), 1);
|
|
4860
4927
|
var HiveGateway = class {
|
|
4861
4928
|
client;
|
|
4862
4929
|
enabled;
|
|
@@ -4866,7 +4933,7 @@ var HiveGateway = class {
|
|
|
4866
4933
|
constructor(baseUrl, token) {
|
|
4867
4934
|
this.enabled = !!token;
|
|
4868
4935
|
if (!this.enabled) {
|
|
4869
|
-
console.log(
|
|
4936
|
+
console.log(import_chalk26.default.dim("\u26A0\uFE0F Hive Gateway disabled (No Token provided). Running in localized mode."));
|
|
4870
4937
|
}
|
|
4871
4938
|
this.client = import_axios18.default.create({
|
|
4872
4939
|
baseURL: baseUrl,
|
|
@@ -4886,84 +4953,28 @@ var HiveGateway = class {
|
|
|
4886
4953
|
if (!this.enabled) return false;
|
|
4887
4954
|
const now = Date.now();
|
|
4888
4955
|
if (now - this.lastSignalTime < this.MIN_INTERVAL_MS) {
|
|
4889
|
-
console.warn(
|
|
4956
|
+
console.warn(import_chalk26.default.yellow("\u23F3 Hive Gateway Throttled. Signal dropped to preventing spam."));
|
|
4890
4957
|
return false;
|
|
4891
4958
|
}
|
|
4892
4959
|
const scrubResult = HiveScrubber.scrub(signal.ruleContent);
|
|
4893
4960
|
if (scrubResult.riskScore > 20) {
|
|
4894
|
-
console.error(
|
|
4961
|
+
console.error(import_chalk26.default.red(`\u{1F6D1} HIVE BLOCKED: Signal contains sensitive data (Risk: ${scrubResult.riskScore})`));
|
|
4895
4962
|
return false;
|
|
4896
4963
|
}
|
|
4897
4964
|
try {
|
|
4898
|
-
console.log(
|
|
4965
|
+
console.log(import_chalk26.default.blue(`\u{1F4E1} Uplinking to Hive... [${signal.vector}]`));
|
|
4899
4966
|
const payload = { ...signal, ruleContent: scrubResult.sanitizedContent };
|
|
4900
4967
|
await this.client.post("/signal", payload);
|
|
4901
4968
|
this.lastSignalTime = now;
|
|
4902
|
-
console.log(
|
|
4969
|
+
console.log(import_chalk26.default.green("\u2705 Signal Received by Hive Core. Knowledge Shared."));
|
|
4903
4970
|
return true;
|
|
4904
4971
|
} catch (error) {
|
|
4905
|
-
console.error(
|
|
4972
|
+
console.error(import_chalk26.default.red(`\u274C Hive Transmission Failed: ${error.message}`));
|
|
4906
4973
|
return false;
|
|
4907
4974
|
}
|
|
4908
4975
|
}
|
|
4909
4976
|
};
|
|
4910
4977
|
|
|
4911
|
-
// src/utils/logger.ts
|
|
4912
|
-
init_cjs_shims();
|
|
4913
|
-
var import_chalk26 = __toESM(require("chalk"), 1);
|
|
4914
|
-
var Logger = class {
|
|
4915
|
-
static formatMessage(level, message, context) {
|
|
4916
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
4917
|
-
let prefix = "";
|
|
4918
|
-
switch (level) {
|
|
4919
|
-
case "INFO" /* INFO */:
|
|
4920
|
-
prefix = import_chalk26.default.blue(`[${"INFO" /* INFO */}]`);
|
|
4921
|
-
break;
|
|
4922
|
-
case "WARN" /* WARN */:
|
|
4923
|
-
prefix = import_chalk26.default.yellow(`[${"WARN" /* WARN */}]`);
|
|
4924
|
-
break;
|
|
4925
|
-
case "ERROR" /* ERROR */:
|
|
4926
|
-
prefix = import_chalk26.default.red(`[${"ERROR" /* ERROR */}]`);
|
|
4927
|
-
break;
|
|
4928
|
-
case "DEBUG" /* DEBUG */:
|
|
4929
|
-
prefix = import_chalk26.default.gray(`[${"DEBUG" /* DEBUG */}]`);
|
|
4930
|
-
break;
|
|
4931
|
-
}
|
|
4932
|
-
let output = `${import_chalk26.default.gray(timestamp)} ${prefix} ${message}`;
|
|
4933
|
-
if (context) {
|
|
4934
|
-
if (context instanceof Error) {
|
|
4935
|
-
output += `
|
|
4936
|
-
${import_chalk26.default.red(context.stack || context.message)}`;
|
|
4937
|
-
} else if (typeof context === "object") {
|
|
4938
|
-
try {
|
|
4939
|
-
output += `
|
|
4940
|
-
${import_chalk26.default.gray(JSON.stringify(context, null, 2))}`;
|
|
4941
|
-
} catch (e) {
|
|
4942
|
-
output += `
|
|
4943
|
-
${import_chalk26.default.gray("[Circular or invalid object]")}`;
|
|
4944
|
-
}
|
|
4945
|
-
} else {
|
|
4946
|
-
output += ` ${String(context)}`;
|
|
4947
|
-
}
|
|
4948
|
-
}
|
|
4949
|
-
return output;
|
|
4950
|
-
}
|
|
4951
|
-
static info(message, context) {
|
|
4952
|
-
console.log(this.formatMessage("INFO" /* INFO */, message, context));
|
|
4953
|
-
}
|
|
4954
|
-
static warn(message, context) {
|
|
4955
|
-
console.warn(this.formatMessage("WARN" /* WARN */, message, context));
|
|
4956
|
-
}
|
|
4957
|
-
static error(message, error) {
|
|
4958
|
-
console.error(this.formatMessage("ERROR" /* ERROR */, message, error));
|
|
4959
|
-
}
|
|
4960
|
-
static debug(message, context) {
|
|
4961
|
-
if (process.env.DEBUG || process.env.RIGSTATE_DEBUG) {
|
|
4962
|
-
console.debug(this.formatMessage("DEBUG" /* DEBUG */, message, context));
|
|
4963
|
-
}
|
|
4964
|
-
}
|
|
4965
|
-
};
|
|
4966
|
-
|
|
4967
4978
|
// src/nexus/dispatcher.ts
|
|
4968
4979
|
var NexusDispatcher = class extends import_events4.default {
|
|
4969
4980
|
context;
|