@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.js
CHANGED
|
@@ -383,136 +383,6 @@ var init_suggest = __esm({
|
|
|
383
383
|
}
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
-
// src/commands/hooks.ts
|
|
387
|
-
var hooks_exports = {};
|
|
388
|
-
__export(hooks_exports, {
|
|
389
|
-
createHooksCommand: () => createHooksCommand
|
|
390
|
-
});
|
|
391
|
-
import { Command as Command4 } from "commander";
|
|
392
|
-
import chalk5 from "chalk";
|
|
393
|
-
import fs2 from "fs/promises";
|
|
394
|
-
import path3 from "path";
|
|
395
|
-
function createHooksCommand() {
|
|
396
|
-
const hooks = new Command4("hooks").description("Manage git hooks for Guardian integration");
|
|
397
|
-
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) => {
|
|
398
|
-
try {
|
|
399
|
-
const gitDir = path3.join(process.cwd(), ".git");
|
|
400
|
-
try {
|
|
401
|
-
await fs2.access(gitDir);
|
|
402
|
-
} catch {
|
|
403
|
-
console.log(chalk5.red("\u274C Not a git repository."));
|
|
404
|
-
console.log(chalk5.dim(' Initialize with "git init" first.'));
|
|
405
|
-
process.exit(1);
|
|
406
|
-
}
|
|
407
|
-
const hooksDir = path3.join(gitDir, "hooks");
|
|
408
|
-
await fs2.mkdir(hooksDir, { recursive: true });
|
|
409
|
-
const preCommitPath = path3.join(hooksDir, "pre-commit");
|
|
410
|
-
let existingContent = "";
|
|
411
|
-
try {
|
|
412
|
-
existingContent = await fs2.readFile(preCommitPath, "utf-8");
|
|
413
|
-
if (existingContent.includes("rigstate")) {
|
|
414
|
-
console.log(chalk5.yellow("\u26A0 Rigstate pre-commit hook already installed."));
|
|
415
|
-
console.log(chalk5.dim(' Use "rigstate hooks uninstall" to remove first.'));
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
} catch {
|
|
419
|
-
}
|
|
420
|
-
let script = PRE_COMMIT_SCRIPT;
|
|
421
|
-
if (options.strict === "all") {
|
|
422
|
-
script = script.replace("--strict=critical", "--strict");
|
|
423
|
-
}
|
|
424
|
-
if (existingContent && !existingContent.includes("rigstate")) {
|
|
425
|
-
const combinedScript = existingContent + "\n\n" + script.replace("#!/bin/sh\n", "");
|
|
426
|
-
await fs2.writeFile(preCommitPath, combinedScript, { mode: 493 });
|
|
427
|
-
console.log(chalk5.green("\u2705 Rigstate hook appended to existing pre-commit."));
|
|
428
|
-
} else {
|
|
429
|
-
await fs2.writeFile(preCommitPath, script, { mode: 493 });
|
|
430
|
-
console.log(chalk5.green("\u2705 Pre-commit hook installed!"));
|
|
431
|
-
}
|
|
432
|
-
console.log(chalk5.dim(` Path: ${preCommitPath}`));
|
|
433
|
-
console.log(chalk5.dim(` Strict level: ${options.strict}`));
|
|
434
|
-
console.log("");
|
|
435
|
-
console.log(chalk5.cyan("Guardian will now check your code before each commit."));
|
|
436
|
-
console.log(chalk5.dim('Use "rigstate hooks uninstall" to remove the hook.'));
|
|
437
|
-
} catch (error) {
|
|
438
|
-
console.error(chalk5.red("Failed to install hook:"), error.message);
|
|
439
|
-
process.exit(1);
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
hooks.command("uninstall").description("Remove Rigstate pre-commit hook").action(async () => {
|
|
443
|
-
try {
|
|
444
|
-
const preCommitPath = path3.join(process.cwd(), ".git", "hooks", "pre-commit");
|
|
445
|
-
try {
|
|
446
|
-
const content = await fs2.readFile(preCommitPath, "utf-8");
|
|
447
|
-
if (!content.includes("rigstate")) {
|
|
448
|
-
console.log(chalk5.yellow("\u26A0 No Rigstate hook found in pre-commit."));
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
if (content.includes("# Rigstate Guardian Pre-commit Hook") && content.trim().split("\n").filter((l) => l && !l.startsWith("#")).length <= 4) {
|
|
452
|
-
await fs2.unlink(preCommitPath);
|
|
453
|
-
console.log(chalk5.green("\u2705 Pre-commit hook removed."));
|
|
454
|
-
} else {
|
|
455
|
-
const lines = content.split("\n");
|
|
456
|
-
const filteredLines = [];
|
|
457
|
-
let inRigstateSection = false;
|
|
458
|
-
for (const line of lines) {
|
|
459
|
-
if (line.includes("Rigstate Guardian Pre-commit Hook")) {
|
|
460
|
-
inRigstateSection = true;
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
if (inRigstateSection && line.includes("exit $?")) {
|
|
464
|
-
inRigstateSection = false;
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
if (!inRigstateSection && !line.includes("rigstate check")) {
|
|
468
|
-
filteredLines.push(line);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
await fs2.writeFile(preCommitPath, filteredLines.join("\n"), { mode: 493 });
|
|
472
|
-
console.log(chalk5.green("\u2705 Rigstate section removed from pre-commit hook."));
|
|
473
|
-
}
|
|
474
|
-
} catch {
|
|
475
|
-
console.log(chalk5.yellow("\u26A0 No pre-commit hook found."));
|
|
476
|
-
}
|
|
477
|
-
} catch (error) {
|
|
478
|
-
console.error(chalk5.red("Failed to uninstall hook:"), error.message);
|
|
479
|
-
process.exit(1);
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
return hooks;
|
|
483
|
-
}
|
|
484
|
-
var PRE_COMMIT_SCRIPT;
|
|
485
|
-
var init_hooks = __esm({
|
|
486
|
-
"src/commands/hooks.ts"() {
|
|
487
|
-
"use strict";
|
|
488
|
-
init_esm_shims();
|
|
489
|
-
PRE_COMMIT_SCRIPT = `#!/bin/sh
|
|
490
|
-
# Rigstate Guardian Pre-commit Hook
|
|
491
|
-
# Installed by: rigstate hooks install
|
|
492
|
-
|
|
493
|
-
# 1. Silent Sentinel Check (Phase 5)
|
|
494
|
-
if [ -f .rigstate/guardian.lock ]; then
|
|
495
|
-
echo "\u{1F6D1} INTERVENTION ACTIVE: Commit blocked by Silent Sentinel."
|
|
496
|
-
echo " A critical violation ('HARD_LOCK') was detected by the Guardian Daemon."
|
|
497
|
-
echo " Please fix the violation to unlock the repo."
|
|
498
|
-
echo ""
|
|
499
|
-
if grep -q "HARD_LOCK_ACTIVE" .rigstate/guardian.lock; then
|
|
500
|
-
cat .rigstate/guardian.lock
|
|
501
|
-
fi
|
|
502
|
-
exit 1
|
|
503
|
-
fi
|
|
504
|
-
|
|
505
|
-
echo "\u{1F6E1}\uFE0F Running Guardian checks..."
|
|
506
|
-
|
|
507
|
-
# Run check with strict mode for critical violations
|
|
508
|
-
rigstate check --staged --strict=critical
|
|
509
|
-
|
|
510
|
-
# Exit with the same code as rigstate check
|
|
511
|
-
exit $?
|
|
512
|
-
`;
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
|
|
516
386
|
// src/utils/skills-provisioner.ts
|
|
517
387
|
var skills_provisioner_exports = {};
|
|
518
388
|
__export(skills_provisioner_exports, {
|
|
@@ -521,9 +391,9 @@ __export(skills_provisioner_exports, {
|
|
|
521
391
|
provisionSkills: () => provisionSkills
|
|
522
392
|
});
|
|
523
393
|
import axios6 from "axios";
|
|
524
|
-
import
|
|
525
|
-
import
|
|
526
|
-
import
|
|
394
|
+
import fs6 from "fs/promises";
|
|
395
|
+
import path7 from "path";
|
|
396
|
+
import chalk8 from "chalk";
|
|
527
397
|
async function provisionSkills(apiUrl, apiKey, projectId, rootDir) {
|
|
528
398
|
const skills = [];
|
|
529
399
|
try {
|
|
@@ -545,18 +415,18 @@ async function provisionSkills(apiUrl, apiKey, projectId, rootDir) {
|
|
|
545
415
|
}
|
|
546
416
|
} catch (e) {
|
|
547
417
|
const msg = e.response?.data?.error || e.message;
|
|
548
|
-
console.log(
|
|
418
|
+
console.log(chalk8.dim(` (Skills API not available: ${msg}, using core library)`));
|
|
549
419
|
}
|
|
550
420
|
if (skills.length === 0) {
|
|
551
421
|
const { getRigstateStandardSkills } = await import("@rigstate/rules-engine");
|
|
552
422
|
const coreSkills = getRigstateStandardSkills();
|
|
553
423
|
skills.push(...coreSkills);
|
|
554
424
|
}
|
|
555
|
-
const skillsDir =
|
|
556
|
-
await
|
|
425
|
+
const skillsDir = path7.join(rootDir, ".agent", "skills");
|
|
426
|
+
await fs6.mkdir(skillsDir, { recursive: true });
|
|
557
427
|
for (const skill of skills) {
|
|
558
|
-
const skillDir =
|
|
559
|
-
await
|
|
428
|
+
const skillDir = path7.join(skillsDir, skill.name);
|
|
429
|
+
await fs6.mkdir(skillDir, { recursive: true });
|
|
560
430
|
const skillContent = `---
|
|
561
431
|
name: ${skill.name}
|
|
562
432
|
description: ${skill.description}
|
|
@@ -569,10 +439,10 @@ ${skill.content}
|
|
|
569
439
|
|
|
570
440
|
---
|
|
571
441
|
*Provisioned by Rigstate CLI. Do not modify manually.*`;
|
|
572
|
-
const skillPath =
|
|
573
|
-
await
|
|
442
|
+
const skillPath = path7.join(skillDir, "SKILL.md");
|
|
443
|
+
await fs6.writeFile(skillPath, skillContent, "utf-8");
|
|
574
444
|
}
|
|
575
|
-
console.log(
|
|
445
|
+
console.log(chalk8.green(` \u2705 Provisioned ${skills.length} skill(s) to .agent/skills/`));
|
|
576
446
|
return skills;
|
|
577
447
|
}
|
|
578
448
|
function generateSkillsDiscoveryBlock(skills) {
|
|
@@ -587,16 +457,16 @@ ${skillBlocks}
|
|
|
587
457
|
</available_skills>`;
|
|
588
458
|
}
|
|
589
459
|
async function jitProvisionSkill(skillId, apiUrl, apiKey, projectId, rootDir) {
|
|
590
|
-
const rulesPath =
|
|
460
|
+
const rulesPath = path7.join(rootDir, ".cursorrules");
|
|
591
461
|
let rulesContent = "";
|
|
592
462
|
try {
|
|
593
|
-
rulesContent = await
|
|
463
|
+
rulesContent = await fs6.readFile(rulesPath, "utf-8");
|
|
594
464
|
} catch (e) {
|
|
595
465
|
return false;
|
|
596
466
|
}
|
|
597
467
|
const isProvisioned = rulesContent.includes(`<name>${skillId}</name>`) || rulesContent.includes(`.agent/skills/${skillId}`);
|
|
598
468
|
if (isProvisioned) return false;
|
|
599
|
-
console.log(
|
|
469
|
+
console.log(chalk8.yellow(` \u26A1 JIT PROVISIONING: Injecting ${skillId}...`));
|
|
600
470
|
try {
|
|
601
471
|
const skills = await provisionSkills(apiUrl, apiKey, projectId, rootDir);
|
|
602
472
|
const skillsBlock = generateSkillsDiscoveryBlock(skills);
|
|
@@ -611,10 +481,10 @@ async function jitProvisionSkill(skillId, apiUrl, apiKey, projectId, rootDir) {
|
|
|
611
481
|
rulesContent = rulesContent.slice(0, insertPoint + 3) + "\n\n" + skillsBlock + "\n" + rulesContent.slice(insertPoint + 3);
|
|
612
482
|
}
|
|
613
483
|
}
|
|
614
|
-
await
|
|
484
|
+
await fs6.writeFile(rulesPath, rulesContent, "utf-8");
|
|
615
485
|
return true;
|
|
616
486
|
} catch (e) {
|
|
617
|
-
console.log(
|
|
487
|
+
console.log(chalk8.red(` Failed to provision skill: ${e.message}`));
|
|
618
488
|
return false;
|
|
619
489
|
}
|
|
620
490
|
}
|
|
@@ -635,13 +505,13 @@ __export(governance_exports, {
|
|
|
635
505
|
performOverride: () => performOverride,
|
|
636
506
|
setSoftLock: () => setSoftLock
|
|
637
507
|
});
|
|
638
|
-
import
|
|
639
|
-
import
|
|
640
|
-
import
|
|
508
|
+
import fs7 from "fs/promises";
|
|
509
|
+
import path8 from "path";
|
|
510
|
+
import chalk9 from "chalk";
|
|
641
511
|
async function getGovernanceConfig(rootDir = process.cwd()) {
|
|
642
512
|
try {
|
|
643
|
-
const configPath =
|
|
644
|
-
const content = await
|
|
513
|
+
const configPath = path8.join(rootDir, "rigstate.config.json");
|
|
514
|
+
const content = await fs7.readFile(configPath, "utf-8");
|
|
645
515
|
const userConfig = JSON.parse(content);
|
|
646
516
|
return {
|
|
647
517
|
governance: {
|
|
@@ -655,37 +525,37 @@ async function getGovernanceConfig(rootDir = process.cwd()) {
|
|
|
655
525
|
}
|
|
656
526
|
async function getSessionState(rootDir = process.cwd()) {
|
|
657
527
|
try {
|
|
658
|
-
const sessionPath =
|
|
659
|
-
const content = await
|
|
528
|
+
const sessionPath = path8.join(rootDir, ".rigstate", "session.json");
|
|
529
|
+
const content = await fs7.readFile(sessionPath, "utf-8");
|
|
660
530
|
return JSON.parse(content);
|
|
661
531
|
} catch (e) {
|
|
662
532
|
return DEFAULT_SESSION;
|
|
663
533
|
}
|
|
664
534
|
}
|
|
665
535
|
async function setSoftLock(reason, violationId, rootDir = process.cwd()) {
|
|
666
|
-
const sessionPath =
|
|
536
|
+
const sessionPath = path8.join(rootDir, ".rigstate", "session.json");
|
|
667
537
|
const state = {
|
|
668
538
|
status: "SOFT_LOCK",
|
|
669
539
|
active_violation: violationId,
|
|
670
540
|
lock_reason: reason,
|
|
671
541
|
last_updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
672
542
|
};
|
|
673
|
-
await
|
|
674
|
-
await
|
|
543
|
+
await fs7.mkdir(path8.dirname(sessionPath), { recursive: true });
|
|
544
|
+
await fs7.writeFile(sessionPath, JSON.stringify(state, null, 2), "utf-8");
|
|
675
545
|
}
|
|
676
546
|
async function clearSoftLock(rootDir = process.cwd()) {
|
|
677
|
-
const sessionPath =
|
|
547
|
+
const sessionPath = path8.join(rootDir, ".rigstate", "session.json");
|
|
678
548
|
const state = {
|
|
679
549
|
...DEFAULT_SESSION,
|
|
680
550
|
last_updated: (/* @__PURE__ */ new Date()).toISOString()
|
|
681
551
|
};
|
|
682
|
-
await
|
|
683
|
-
await
|
|
552
|
+
await fs7.mkdir(path8.dirname(sessionPath), { recursive: true });
|
|
553
|
+
await fs7.writeFile(sessionPath, JSON.stringify(state, null, 2), "utf-8");
|
|
684
554
|
}
|
|
685
555
|
async function performOverride(violationId, reason, rootDir = process.cwd()) {
|
|
686
556
|
const config2 = await getGovernanceConfig(rootDir);
|
|
687
557
|
if (!config2.governance.allow_overrides) {
|
|
688
|
-
console.log(
|
|
558
|
+
console.log(chalk9.red("\u274C Overrides are disabled for this project."));
|
|
689
559
|
return false;
|
|
690
560
|
}
|
|
691
561
|
await clearSoftLock(rootDir);
|
|
@@ -722,22 +592,22 @@ var watchdog_exports = {};
|
|
|
722
592
|
__export(watchdog_exports, {
|
|
723
593
|
runGuardianWatchdog: () => runGuardianWatchdog
|
|
724
594
|
});
|
|
725
|
-
import
|
|
726
|
-
import
|
|
727
|
-
import
|
|
595
|
+
import fs8 from "fs/promises";
|
|
596
|
+
import path9 from "path";
|
|
597
|
+
import chalk10 from "chalk";
|
|
728
598
|
import axios7 from "axios";
|
|
729
599
|
async function countLines(filePath) {
|
|
730
600
|
try {
|
|
731
|
-
const content = await
|
|
601
|
+
const content = await fs8.readFile(filePath, "utf-8");
|
|
732
602
|
return content.split("\n").length;
|
|
733
603
|
} catch (e) {
|
|
734
604
|
return 0;
|
|
735
605
|
}
|
|
736
606
|
}
|
|
737
607
|
async function getFiles(dir, extension) {
|
|
738
|
-
const entries = await
|
|
608
|
+
const entries = await fs8.readdir(dir, { withFileTypes: true });
|
|
739
609
|
const files = await Promise.all(entries.map(async (entry) => {
|
|
740
|
-
const res =
|
|
610
|
+
const res = path9.resolve(dir, entry.name);
|
|
741
611
|
if (entry.isDirectory()) {
|
|
742
612
|
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".next" || entry.name === "dist") return [];
|
|
743
613
|
return getFiles(res, extension);
|
|
@@ -765,8 +635,8 @@ async function fetchRulesFromApi(projectId) {
|
|
|
765
635
|
}
|
|
766
636
|
} catch (error) {
|
|
767
637
|
try {
|
|
768
|
-
const cachePath =
|
|
769
|
-
const content = await
|
|
638
|
+
const cachePath = path9.join(process.cwd(), CACHE_FILE);
|
|
639
|
+
const content = await fs8.readFile(cachePath, "utf-8");
|
|
770
640
|
const cached = JSON.parse(content);
|
|
771
641
|
if (cached.settings) {
|
|
772
642
|
return {
|
|
@@ -785,7 +655,7 @@ async function fetchRulesFromApi(projectId) {
|
|
|
785
655
|
};
|
|
786
656
|
}
|
|
787
657
|
async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
788
|
-
console.log(
|
|
658
|
+
console.log(chalk10.bold("\n\u{1F6E1}\uFE0F Active Guardian Watchdog Initiated..."));
|
|
789
659
|
let lmax = settings.lmax || DEFAULT_LMAX;
|
|
790
660
|
let lmaxWarning = settings.lmax_warning || DEFAULT_LMAX_WARNING;
|
|
791
661
|
let ruleSource = settings.lmax ? "Settings (Passed)" : "Default";
|
|
@@ -795,47 +665,47 @@ async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
|
795
665
|
lmaxWarning = apiRules.lmaxWarning;
|
|
796
666
|
ruleSource = apiRules.source;
|
|
797
667
|
}
|
|
798
|
-
console.log(
|
|
668
|
+
console.log(chalk10.dim(`Governance Rules: L_max=${lmax}, L_max_warning=${lmaxWarning}, Source: ${ruleSource}`));
|
|
799
669
|
const targetExtensions = [".ts", ".tsx"];
|
|
800
670
|
let scanTarget = rootPath;
|
|
801
|
-
const webSrc =
|
|
671
|
+
const webSrc = path9.join(rootPath, "apps", "web", "src");
|
|
802
672
|
try {
|
|
803
|
-
await
|
|
673
|
+
await fs8.access(webSrc);
|
|
804
674
|
scanTarget = webSrc;
|
|
805
675
|
} catch {
|
|
806
676
|
}
|
|
807
|
-
console.log(
|
|
677
|
+
console.log(chalk10.dim(`Scanning target: ${path9.relative(process.cwd(), scanTarget)}`));
|
|
808
678
|
const files = await getFiles(scanTarget, targetExtensions);
|
|
809
679
|
let violations = 0;
|
|
810
680
|
let warnings = 0;
|
|
811
681
|
const results = [];
|
|
812
682
|
for (const file of files) {
|
|
813
683
|
const lines = await countLines(file);
|
|
814
|
-
const relPath =
|
|
684
|
+
const relPath = path9.relative(rootPath, file);
|
|
815
685
|
if (lines > lmax) {
|
|
816
686
|
results.push({ file: relPath, lines, status: "VIOLATION" });
|
|
817
687
|
violations++;
|
|
818
|
-
console.log(
|
|
688
|
+
console.log(chalk10.red(`[VIOLATION] ${relPath}: ${lines} lines (Limit: ${lmax})`));
|
|
819
689
|
} else if (lines > lmaxWarning) {
|
|
820
690
|
results.push({ file: relPath, lines, status: "WARNING" });
|
|
821
691
|
warnings++;
|
|
822
|
-
console.log(
|
|
692
|
+
console.log(chalk10.yellow(`[WARNING] ${relPath}: ${lines} lines (Threshold: ${lmaxWarning})`));
|
|
823
693
|
}
|
|
824
694
|
}
|
|
825
695
|
if (violations === 0 && warnings === 0) {
|
|
826
|
-
console.log(
|
|
696
|
+
console.log(chalk10.green(`\u2714 All ${files.length} files are within governance limits.`));
|
|
827
697
|
} else {
|
|
828
|
-
console.log("\n" +
|
|
829
|
-
console.log(
|
|
830
|
-
console.log(
|
|
698
|
+
console.log("\n" + chalk10.bold("Summary:"));
|
|
699
|
+
console.log(chalk10.red(`Violations: ${violations}`));
|
|
700
|
+
console.log(chalk10.yellow(`Warnings: ${warnings}`));
|
|
831
701
|
const { getGovernanceConfig: getGovernanceConfig2, setSoftLock: setSoftLock2, InterventionLevel: InterventionLevel2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
|
|
832
702
|
const { governance } = await getGovernanceConfig2(rootPath);
|
|
833
|
-
console.log(
|
|
703
|
+
console.log(chalk10.dim(`Intervention Level: ${InterventionLevel2[governance.intervention_level] || "UNKNOWN"} (${governance.intervention_level})`));
|
|
834
704
|
if (violations > 0) {
|
|
835
|
-
console.log(
|
|
705
|
+
console.log(chalk10.red.bold("\nCRITICAL: Governance violations detected. Immediate refactoring required."));
|
|
836
706
|
if (governance.intervention_level >= InterventionLevel2.SENTINEL) {
|
|
837
|
-
console.log(
|
|
838
|
-
console.log(
|
|
707
|
+
console.log(chalk10.red.bold("\u{1F6D1} SENTINEL MODE: Session SOFT_LOCKED until resolved."));
|
|
708
|
+
console.log(chalk10.red(' Run "rigstate override <id> --reason \\"...\\"" if this is an emergency.'));
|
|
839
709
|
await setSoftLock2("Sentinel Mode: Governance Violations Detected", "ARC-VIOLATION", rootPath);
|
|
840
710
|
}
|
|
841
711
|
}
|
|
@@ -858,9 +728,9 @@ async function runGuardianWatchdog(rootPath, settings = {}, projectId) {
|
|
|
858
728
|
}, {
|
|
859
729
|
headers: { Authorization: `Bearer ${apiKey}` }
|
|
860
730
|
});
|
|
861
|
-
console.log(
|
|
731
|
+
console.log(chalk10.dim("\u2714 Violations synced to Rigstate Cloud."));
|
|
862
732
|
} catch (e) {
|
|
863
|
-
console.log(
|
|
733
|
+
console.log(chalk10.dim("\u26A0 Cloud sync skipped: " + (e.message || "Unknown")));
|
|
864
734
|
}
|
|
865
735
|
}
|
|
866
736
|
}
|
|
@@ -1757,7 +1627,7 @@ var require_package = __commonJS({
|
|
|
1757
1627
|
"package.json"(exports, module) {
|
|
1758
1628
|
module.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",
|
|
@@ -1867,67 +1737,70 @@ Your API key has been securely stored. You can now use "rigstate scan" to audit
|
|
|
1867
1737
|
// src/commands/link.ts
|
|
1868
1738
|
init_esm_shims();
|
|
1869
1739
|
init_config();
|
|
1870
|
-
import { Command as
|
|
1871
|
-
import
|
|
1872
|
-
import
|
|
1873
|
-
import
|
|
1740
|
+
import { Command as Command4 } from "commander";
|
|
1741
|
+
import fs2 from "fs/promises";
|
|
1742
|
+
import path3 from "path";
|
|
1743
|
+
import chalk5 from "chalk";
|
|
1874
1744
|
import os from "os";
|
|
1875
1745
|
function createLinkCommand() {
|
|
1876
|
-
return new
|
|
1746
|
+
return new Command4("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 = path3.join(os.homedir(), ".rigstate", "config.json");
|
|
1749
|
+
const globalData = await fs2.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(chalk5.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 = path3.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 fs2.writeFile(manifestPath, JSON.stringify(content, null, 2), "utf-8");
|
|
1774
|
+
console.log(chalk5.green(`\u2714 Linked to project ID: ${projectId}`));
|
|
1775
|
+
console.log(chalk5.dim(`Created local context manifest at .rigstate`));
|
|
1903
1776
|
console.log("");
|
|
1904
|
-
console.log(
|
|
1777
|
+
console.log(chalk5.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(chalk5.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(chalk5.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(chalk5.blue("\u{1F6E1}\uFE0F Checking immunity system..."));
|
|
1917
1790
|
await installHooks(process.cwd());
|
|
1918
1791
|
console.log("");
|
|
1919
|
-
console.log(
|
|
1792
|
+
console.log(chalk5.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(chalk5.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(chalk5.yellow('\u26A0\uFE0F Not authenticated. Run "rigstate login" to enable automation features.'));
|
|
1929
1802
|
} else {
|
|
1930
|
-
console.error(
|
|
1803
|
+
console.error(chalk5.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(path25.join(cwd, ".git"));
|
|
1940
1813
|
} catch {
|
|
1941
|
-
console.log(
|
|
1814
|
+
console.log(chalk5.dim(" (Not a git repository, skipping hooks)"));
|
|
1942
1815
|
return;
|
|
1943
1816
|
}
|
|
1944
1817
|
const hooksDir = path25.join(cwd, ".husky");
|
|
1945
1818
|
try {
|
|
1946
|
-
const { installHooks: runInstall } = await Promise.resolve().then(() => (init_hooks(), hooks_exports));
|
|
1947
1819
|
const preCommitPath = path25.join(cwd, ".git/hooks/pre-commit");
|
|
1948
1820
|
try {
|
|
1949
1821
|
await fs23.access(preCommitPath);
|
|
1950
|
-
console.log(
|
|
1822
|
+
console.log(chalk5.green(" \u2714 Git hooks already active"));
|
|
1951
1823
|
} catch {
|
|
1952
|
-
console.log(
|
|
1824
|
+
console.log(chalk5.yellow(' \u26A0\uFE0F Git hooks missing. Run "rigstate hooks install" to secure repo.'));
|
|
1953
1825
|
}
|
|
1954
1826
|
} catch (e) {
|
|
1955
1827
|
}
|
|
@@ -1958,22 +1830,22 @@ async function installHooks(cwd) {
|
|
|
1958
1830
|
// src/commands/scan.ts
|
|
1959
1831
|
init_esm_shims();
|
|
1960
1832
|
init_config();
|
|
1961
|
-
import { Command as
|
|
1962
|
-
import
|
|
1833
|
+
import { Command as Command5 } from "commander";
|
|
1834
|
+
import chalk6 from "chalk";
|
|
1963
1835
|
import ora3 from "ora";
|
|
1964
1836
|
import axios4 from "axios";
|
|
1965
1837
|
import { glob } from "glob";
|
|
1966
|
-
import
|
|
1967
|
-
import
|
|
1838
|
+
import fs4 from "fs/promises";
|
|
1839
|
+
import path5 from "path";
|
|
1968
1840
|
|
|
1969
1841
|
// src/utils/files.ts
|
|
1970
1842
|
init_esm_shims();
|
|
1971
|
-
import
|
|
1972
|
-
import
|
|
1843
|
+
import fs3 from "fs/promises";
|
|
1844
|
+
import path4 from "path";
|
|
1973
1845
|
async function readGitignore(dir) {
|
|
1974
|
-
const gitignorePath =
|
|
1846
|
+
const gitignorePath = path4.join(dir, ".gitignore");
|
|
1975
1847
|
try {
|
|
1976
|
-
const content = await
|
|
1848
|
+
const content = await fs3.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 = path4.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 Command5("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 = ora3();
|
|
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
|
+
chalk6.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 = path5.resolve(process.cwd(), targetPath);
|
|
1930
|
+
spinner.start(`Scanning ${chalk6.cyan(scanPath)}...`);
|
|
2059
1931
|
const gitignorePatterns = await readGitignore(scanPath);
|
|
2060
|
-
const pattern =
|
|
1932
|
+
const pattern = path5.join(scanPath, "**/*");
|
|
2061
1933
|
const allFiles = await 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 = path5.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(chalk6.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 = path5.relative(scanPath, filePath);
|
|
2081
1953
|
spinner.text = `Scanning ${i + 1}/${codeFiles.length}: ${relativePath}`;
|
|
2082
1954
|
try {
|
|
2083
|
-
const content = await
|
|
1955
|
+
const content = await fs4.readFile(filePath, "utf-8");
|
|
2084
1956
|
const response = await axios4.post(
|
|
2085
1957
|
`${apiUrl}/api/v1/audit`,
|
|
2086
1958
|
{
|
|
@@ -2116,15 +1988,15 @@ function createScanCommand() {
|
|
|
2116
1988
|
}
|
|
2117
1989
|
} catch (fileError) {
|
|
2118
1990
|
if (axios4.isAxiosError(fileError)) {
|
|
2119
|
-
console.warn(
|
|
1991
|
+
console.warn(chalk6.yellow(`
|
|
2120
1992
|
\u26A0\uFE0F Skipping ${relativePath}: ${fileError.message}`));
|
|
2121
1993
|
} else {
|
|
2122
|
-
console.warn(
|
|
1994
|
+
console.warn(chalk6.yellow(`
|
|
2123
1995
|
\u26A0\uFE0F Error reading ${relativePath}`));
|
|
2124
1996
|
}
|
|
2125
1997
|
}
|
|
2126
1998
|
}
|
|
2127
|
-
spinner.succeed(
|
|
1999
|
+
spinner.succeed(chalk6.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(chalk6.red("\u274C Scan failed"));
|
|
2143
2015
|
if (axios4.isAxiosError(error)) {
|
|
2144
2016
|
if (error.response) {
|
|
2145
|
-
console.error(
|
|
2017
|
+
console.error(chalk6.red("API Error:"), error.response.data);
|
|
2146
2018
|
} else if (error.request) {
|
|
2147
2019
|
console.error(
|
|
2148
|
-
|
|
2020
|
+
chalk6.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(chalk6.red("Error:"), error.message);
|
|
2153
2025
|
}
|
|
2154
2026
|
} else {
|
|
2155
2027
|
console.error(
|
|
2156
|
-
|
|
2028
|
+
chalk6.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" + chalk6.bold("\u{1F4CA} Scan Summary"));
|
|
2039
|
+
console.log(chalk6.dim("\u2500".repeat(60)));
|
|
2040
|
+
console.log(`Total Files Scanned: ${chalk6.cyan(summary.total_files)}`);
|
|
2041
|
+
console.log(`Total Issues Found: ${chalk6.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" + chalk6.bold("\u{1F50D} Detailed Results"));
|
|
2051
|
+
console.log(chalk6.dim("\u2500".repeat(60)));
|
|
2180
2052
|
results.forEach((result) => {
|
|
2181
2053
|
if (result.issues && result.issues.length > 0) {
|
|
2182
2054
|
console.log(`
|
|
2183
|
-
${
|
|
2055
|
+
${chalk6.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 ? chalk6.dim(`:${issue.line}`) : "";
|
|
2187
2059
|
console.log(
|
|
2188
2060
|
` ${severityColor(`[${issue.severity.toUpperCase()}]`)} ${issue.type}${lineInfo}`
|
|
2189
2061
|
);
|
|
2190
|
-
console.log(` ${
|
|
2062
|
+
console.log(` ${chalk6.dim(issue.message)}`);
|
|
2191
2063
|
});
|
|
2192
2064
|
}
|
|
2193
2065
|
});
|
|
2194
2066
|
}
|
|
2195
|
-
console.log("\n" +
|
|
2067
|
+
console.log("\n" + chalk6.dim("\u2500".repeat(60)));
|
|
2196
2068
|
}
|
|
2197
2069
|
function getSeverityColor(severity) {
|
|
2198
2070
|
switch (severity.toLowerCase()) {
|
|
2199
2071
|
case "critical":
|
|
2200
|
-
return
|
|
2072
|
+
return chalk6.red.bold;
|
|
2201
2073
|
case "high":
|
|
2202
|
-
return
|
|
2074
|
+
return chalk6.red;
|
|
2203
2075
|
case "medium":
|
|
2204
|
-
return
|
|
2076
|
+
return chalk6.yellow;
|
|
2205
2077
|
case "low":
|
|
2206
|
-
return
|
|
2078
|
+
return chalk6.blue;
|
|
2207
2079
|
case "info":
|
|
2208
|
-
return
|
|
2080
|
+
return chalk6.gray;
|
|
2209
2081
|
default:
|
|
2210
|
-
return
|
|
2082
|
+
return chalk6.white;
|
|
2211
2083
|
}
|
|
2212
2084
|
}
|
|
2213
2085
|
|
|
2214
2086
|
// src/commands/fix.ts
|
|
2215
2087
|
init_esm_shims();
|
|
2216
2088
|
init_config();
|
|
2217
|
-
import { Command as
|
|
2218
|
-
import
|
|
2089
|
+
import { Command as Command6 } from "commander";
|
|
2090
|
+
import chalk7 from "chalk";
|
|
2219
2091
|
import ora4 from "ora";
|
|
2220
2092
|
import axios5 from "axios";
|
|
2221
2093
|
import { glob as glob2 } from "glob";
|
|
2222
|
-
import
|
|
2223
|
-
import
|
|
2094
|
+
import fs5 from "fs/promises";
|
|
2095
|
+
import path6 from "path";
|
|
2224
2096
|
import inquirer from "inquirer";
|
|
2225
2097
|
import * as Diff from "diff";
|
|
2226
2098
|
function createFixCommand() {
|
|
2227
|
-
return new
|
|
2099
|
+
return new Command6("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 = ora4();
|
|
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(chalk7.yellow("\u26A0\uFE0F Project ID is required for fixing. Using default or pass --project <id>"));
|
|
2235
2107
|
}
|
|
2236
|
-
const scanPath =
|
|
2108
|
+
const scanPath = path6.resolve(process.cwd(), targetPath);
|
|
2237
2109
|
const gitignorePatterns = await readGitignore(scanPath);
|
|
2238
|
-
const pattern =
|
|
2110
|
+
const pattern = path6.join(scanPath, "**/*");
|
|
2239
2111
|
const allFiles = await glob2(pattern, { nodir: true, dot: false, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
2240
2112
|
const codeFiles = allFiles.filter((file) => {
|
|
2241
|
-
const relativePath =
|
|
2113
|
+
const relativePath = path6.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(chalk7.yellow("No code files found."));
|
|
2246
2118
|
return;
|
|
2247
2119
|
}
|
|
2248
|
-
console.log(
|
|
2120
|
+
console.log(chalk7.bold(`
|
|
2249
2121
|
\u{1F9E0} Rigstate Fix Mode`));
|
|
2250
|
-
console.log(
|
|
2122
|
+
console.log(chalk7.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 = path6.relative(scanPath, filePath);
|
|
2256
2128
|
spinner.start(`Analyzing ${relativePath}...`);
|
|
2257
2129
|
try {
|
|
2258
|
-
const content = await
|
|
2130
|
+
const content = await fs5.readFile(filePath, "utf-8");
|
|
2259
2131
|
const response = await axios5.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
|
+
${chalk7.bold(relativePath)}: Found ${fixableIssues.length} fixable issues.`);
|
|
2270
2142
|
for (const issue of fixableIssues) {
|
|
2271
|
-
console.log(
|
|
2143
|
+
console.log(chalk7.red(`
|
|
2272
2144
|
[${issue.type}] ${issue.title}`));
|
|
2273
|
-
console.log(
|
|
2145
|
+
console.log(chalk7.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 inquirer.prompt([{
|
|
2277
2149
|
type: "confirm",
|
|
2278
2150
|
name: "apply",
|
|
2279
|
-
message: `Apply this fix to ${
|
|
2151
|
+
message: `Apply this fix to ${chalk7.cyan(relativePath)}?`,
|
|
2280
2152
|
default: true
|
|
2281
2153
|
}]);
|
|
2282
2154
|
if (apply) {
|
|
2283
|
-
await
|
|
2284
|
-
console.log(
|
|
2155
|
+
await fs5.writeFile(filePath, issue.fixed_content);
|
|
2156
|
+
console.log(chalk7.green(`\u2705 Fixed applied!`));
|
|
2285
2157
|
fixedCount++;
|
|
2286
2158
|
if (issue.related_step_id) {
|
|
2287
2159
|
const { completeStep } = await inquirer.prompt([{
|
|
@@ -2297,15 +2169,15 @@ ${chalk8.bold(relativePath)}: Found ${fixableIssues.length} fixable issues.`);
|
|
|
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(chalk7.green(`\u{1F680} Roadmap updated! Mission Control is in sync.`));
|
|
2301
2173
|
} catch (err) {
|
|
2302
|
-
console.error(
|
|
2174
|
+
console.error(chalk7.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(chalk7.dim("Skipped."));
|
|
2309
2181
|
}
|
|
2310
2182
|
}
|
|
2311
2183
|
} else {
|
|
@@ -2315,11 +2187,11 @@ ${chalk8.bold(relativePath)}: Found ${fixableIssues.length} fixable issues.`);
|
|
|
2315
2187
|
}
|
|
2316
2188
|
}
|
|
2317
2189
|
spinner.stop();
|
|
2318
|
-
console.log(
|
|
2190
|
+
console.log(chalk7.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(chalk7.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);
|
|
@@ -2330,14 +2202,14 @@ ${chalk8.bold(relativePath)}: Found ${fixableIssues.length} fixable issues.`);
|
|
|
2330
2202
|
// src/commands/sync.ts
|
|
2331
2203
|
init_esm_shims();
|
|
2332
2204
|
init_config();
|
|
2333
|
-
import { Command as
|
|
2334
|
-
import
|
|
2205
|
+
import { Command as Command7 } from "commander";
|
|
2206
|
+
import chalk11 from "chalk";
|
|
2335
2207
|
import ora5 from "ora";
|
|
2336
2208
|
import axios8 from "axios";
|
|
2337
|
-
import
|
|
2338
|
-
import
|
|
2209
|
+
import fs9 from "fs/promises";
|
|
2210
|
+
import path10 from "path";
|
|
2339
2211
|
function createSyncCommand() {
|
|
2340
|
-
const sync = new
|
|
2212
|
+
const sync = new Command7("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 = ora5("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 = path10.join(process.cwd(), ".rigstate");
|
|
2227
|
+
const manifestContent = await fs9.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 = path10.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 fs9.writeFile(targetPath, fileContent, "utf-8");
|
|
2386
2258
|
try {
|
|
2387
|
-
const manifestPath =
|
|
2259
|
+
const manifestPath = path10.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 fs9.writeFile(manifestPath, JSON.stringify(manifestContent, null, 2), "utf-8");
|
|
2395
2267
|
} catch (e) {
|
|
2396
2268
|
}
|
|
2397
|
-
console.log(
|
|
2269
|
+
console.log(chalk11.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 = path10.join(process.cwd(), ".cursorrules");
|
|
2402
2274
|
try {
|
|
2403
|
-
let rulesContent = await
|
|
2275
|
+
let rulesContent = await fs9.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 fs9.writeFile(cursorRulesPath, rulesContent, "utf-8");
|
|
2289
|
+
console.log(chalk11.dim(` Updated .cursorrules with skills discovery block`));
|
|
2418
2290
|
} catch (e) {
|
|
2419
2291
|
}
|
|
2420
2292
|
} catch (e) {
|
|
2421
|
-
console.log(
|
|
2293
|
+
console.log(chalk11.yellow(` \u26A0 Skills provisioning skipped: ${e.message}`));
|
|
2422
2294
|
}
|
|
2423
2295
|
try {
|
|
2424
|
-
const logPath =
|
|
2296
|
+
const logPath = path10.join(process.cwd(), ".rigstate", "logs", "last_execution.json");
|
|
2425
2297
|
try {
|
|
2426
|
-
const logContent = await
|
|
2298
|
+
const logContent = await fs9.readFile(logPath, "utf-8");
|
|
2427
2299
|
const logData = JSON.parse(logContent);
|
|
2428
2300
|
if (logData.task_summary) {
|
|
2429
2301
|
await axios8.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 fs9.unlink(logPath);
|
|
2309
|
+
console.log(chalk11.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(chalk11.green(`Synced ${roadmap.length} roadmap steps for project "${project}"`));
|
|
2318
|
+
console.log(chalk11.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(chalk11.bold("\n\u{1F4E1} Agent Bridge Heartbeat..."));
|
|
2451
2323
|
try {
|
|
2452
2324
|
const bridgeResponse = await axios8.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(chalk11.yellow(`\u26A0 Bridge Alert: ${pending.length} pending, ${approved.length} approved tasks found.`));
|
|
2334
|
+
console.log(chalk11.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(chalk11.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(chalk11.cyan(`\u{1F3D3} Pong! Acknowledged heartbeat signal [${ping.id}]`));
|
|
2476
2348
|
}
|
|
2477
2349
|
}
|
|
2478
2350
|
} catch (e) {
|
|
2479
|
-
console.log(
|
|
2351
|
+
console.log(chalk11.yellow(`\u26A0 Could not verify Bridge status: ${e.message}`));
|
|
2480
2352
|
}
|
|
2481
2353
|
if (options.project) {
|
|
2482
|
-
console.log(
|
|
2354
|
+
console.log(chalk11.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 = path10.join(process.cwd(), "supabase", "migrations");
|
|
2358
|
+
const files = await fs9.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(chalk11.dim(`
|
|
2491
2363
|
\u{1F6E1} Migration Guard:`));
|
|
2492
|
-
console.log(
|
|
2493
|
-
console.log(
|
|
2364
|
+
console.log(chalk11.dim(` Latest Local: ${latestMigration}`));
|
|
2365
|
+
console.log(chalk11.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 = path10.join(process.cwd(), ".env.local");
|
|
2506
2378
|
let localContent = "";
|
|
2507
2379
|
try {
|
|
2508
|
-
localContent = await
|
|
2380
|
+
localContent = await fs9.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(chalk11.bold("\n\u{1F510} Sovereign Foundation (Vault):"));
|
|
2385
|
+
console.log(chalk11.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 fs9.writeFile(localEnvPath, vaultContent, "utf-8");
|
|
2394
|
+
console.log(chalk11.green(" \u2705 .env.local synchronized with Vault."));
|
|
2523
2395
|
} else {
|
|
2524
|
-
console.log(
|
|
2396
|
+
console.log(chalk11.dim(" Skipped vault sync."));
|
|
2525
2397
|
}
|
|
2526
2398
|
} else {
|
|
2527
|
-
console.log(
|
|
2399
|
+
console.log(chalk11.dim("\n\u{1F510} Sovereign Foundation: Synced."));
|
|
2528
2400
|
}
|
|
2529
2401
|
}
|
|
2530
2402
|
} catch (e) {
|
|
2531
2403
|
}
|
|
2532
|
-
console.log(
|
|
2404
|
+
console.log(chalk11.dim("\n\u{1F6E1}\uFE0F System Integrity Check..."));
|
|
2533
2405
|
await checkSystemIntegrity(apiUrl, apiKey, projectId);
|
|
2534
2406
|
} catch (error) {
|
|
2535
2407
|
if (axios8.isAxiosError(error)) {
|
|
2536
2408
|
const message = error.response?.data?.error || error.message;
|
|
2537
|
-
spinner.fail(
|
|
2409
|
+
spinner.fail(chalk11.red(`Sync failed: ${message}`));
|
|
2538
2410
|
} else {
|
|
2539
|
-
spinner.fail(
|
|
2411
|
+
spinner.fail(chalk11.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(chalk11.green(` \u2705 Migrations synced (${migrations.count} versions)`));
|
|
2556
2428
|
} else {
|
|
2557
|
-
console.log(
|
|
2429
|
+
console.log(chalk11.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(chalk11.dim(` Missing: ${migrations.missing.slice(0, 3).join(", ")}${migrations.missing.length > 3 ? "..." : ""}`));
|
|
2560
2432
|
}
|
|
2561
|
-
console.log(
|
|
2433
|
+
console.log(chalk11.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(chalk11.green(` \u2705 RLS Audit Passed (${rls.table_count} tables secured)`));
|
|
2567
2439
|
} else {
|
|
2568
|
-
console.log(
|
|
2440
|
+
console.log(chalk11.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(chalk11.red(` - ${table}`));
|
|
2571
2443
|
});
|
|
2572
|
-
console.log(
|
|
2444
|
+
console.log(chalk11.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(chalk11.green(" \u2705 Guardian: No active violations"));
|
|
2578
2450
|
} else {
|
|
2579
|
-
console.log(
|
|
2580
|
-
console.log(
|
|
2451
|
+
console.log(chalk11.yellow(` \u26A0\uFE0F Guardian: ${guardian_violations.count} active violations`));
|
|
2452
|
+
console.log(chalk11.dim(' Run "rigstate check" for details.'));
|
|
2581
2453
|
}
|
|
2582
2454
|
}
|
|
2583
2455
|
}
|
|
2584
2456
|
} catch (e) {
|
|
2585
|
-
console.log(
|
|
2457
|
+
console.log(chalk11.dim(" (System integrity check skipped - API endpoint not available)"));
|
|
2586
2458
|
}
|
|
2587
2459
|
}
|
|
2588
2460
|
|
|
2589
2461
|
// src/commands/init.ts
|
|
2590
2462
|
init_esm_shims();
|
|
2591
|
-
import { Command as
|
|
2592
|
-
import
|
|
2593
|
-
import
|
|
2594
|
-
import
|
|
2463
|
+
import { Command as Command8 } from "commander";
|
|
2464
|
+
import chalk12 from "chalk";
|
|
2465
|
+
import fs11 from "fs/promises";
|
|
2466
|
+
import path12 from "path";
|
|
2595
2467
|
import ora6 from "ora";
|
|
2596
2468
|
import { execSync } from "child_process";
|
|
2597
2469
|
|
|
2598
2470
|
// src/utils/manifest.ts
|
|
2599
2471
|
init_esm_shims();
|
|
2600
|
-
import
|
|
2601
|
-
import
|
|
2472
|
+
import fs10 from "fs/promises";
|
|
2473
|
+
import path11 from "path";
|
|
2602
2474
|
async function loadManifest() {
|
|
2603
2475
|
try {
|
|
2604
|
-
const manifestPath =
|
|
2605
|
-
const content = await
|
|
2476
|
+
const manifestPath = path11.join(process.cwd(), ".rigstate");
|
|
2477
|
+
const content = await fs10.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
|
import axios9 from "axios";
|
|
2615
2487
|
function createInitCommand() {
|
|
2616
|
-
return new
|
|
2488
|
+
return new Command8("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 = ora6("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(chalk12.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(chalk12.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(chalk12.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(chalk12.green(`Created new project: ${newName}`));
|
|
2736
2608
|
} catch (e) {
|
|
2737
|
-
spinner.fail(
|
|
2609
|
+
spinner.fail(chalk12.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 = path12.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 fs11.writeFile(manifestPath, JSON.stringify(manifestContent, null, 2), "utf-8");
|
|
2754
2626
|
try {
|
|
2755
|
-
await
|
|
2627
|
+
await fs11.access(".git");
|
|
2756
2628
|
} catch {
|
|
2757
2629
|
spinner.text = "Initializing git repository...";
|
|
2758
2630
|
execSync("git init", { stdio: "ignore" });
|
|
2759
2631
|
}
|
|
2760
|
-
spinner.succeed(
|
|
2632
|
+
spinner.succeed(chalk12.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(chalk12.blue("Next steps:"));
|
|
2636
|
+
console.log(chalk12.dim(" rigstate sync - Sync roadmap and context"));
|
|
2637
|
+
console.log(chalk12.dim(" rigstate watch - Start development loop"));
|
|
2638
|
+
console.log(chalk12.dim(" rigstate focus - Get current task"));
|
|
2767
2639
|
} catch (e) {
|
|
2768
|
-
spinner.fail(
|
|
2640
|
+
spinner.fail(chalk12.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 = path12.join(process.cwd(), ".cursorrules");
|
|
2656
|
+
await fs11.writeFile(rulesPath, response.data.rules, "utf-8");
|
|
2657
|
+
spinner.succeed(chalk12.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 = path12.join(process.cwd(), file.path);
|
|
2662
|
+
const targetDir = path12.dirname(targetPath);
|
|
2663
|
+
await fs11.mkdir(targetDir, { recursive: true });
|
|
2792
2664
|
try {
|
|
2793
|
-
await
|
|
2665
|
+
await fs11.access(targetPath);
|
|
2794
2666
|
if (!force && !file.path.startsWith(".cursor/rules/")) {
|
|
2795
|
-
console.log(
|
|
2667
|
+
console.log(chalk12.dim(` ${file.path} already exists. Skipping.`));
|
|
2796
2668
|
continue;
|
|
2797
2669
|
}
|
|
2798
2670
|
} catch {
|
|
2799
2671
|
}
|
|
2800
|
-
await
|
|
2672
|
+
await fs11.writeFile(targetPath, file.content, "utf-8");
|
|
2801
2673
|
}
|
|
2802
2674
|
if (files.length > 0) {
|
|
2803
|
-
const legacyPath =
|
|
2675
|
+
const legacyPath = path12.join(process.cwd(), ".cursorrules");
|
|
2804
2676
|
try {
|
|
2805
|
-
const stats = await
|
|
2677
|
+
const stats = await fs11.stat(legacyPath);
|
|
2806
2678
|
if (stats.isFile()) {
|
|
2807
|
-
await
|
|
2808
|
-
console.log(
|
|
2679
|
+
await fs11.rename(legacyPath, `${legacyPath}.bak`);
|
|
2680
|
+
console.log(chalk12.dim(" Moved legacy .cursorrules to .cursorrules.bak"));
|
|
2809
2681
|
}
|
|
2810
2682
|
} catch (e) {
|
|
2811
2683
|
}
|
|
2812
2684
|
}
|
|
2813
|
-
spinner.succeed(
|
|
2685
|
+
spinner.succeed(chalk12.green(`\u2714 Generated ${files.length} rule files (v${response.data.version || "3.0"})`));
|
|
2814
2686
|
} else {
|
|
2815
|
-
spinner.info(
|
|
2687
|
+
spinner.info(chalk12.dim(" Rules generation skipped (API response invalid)"));
|
|
2816
2688
|
}
|
|
2817
2689
|
} catch (e) {
|
|
2818
|
-
spinner.info(
|
|
2690
|
+
spinner.info(chalk12.dim(` Rules generation failed: ${e.message}`));
|
|
2819
2691
|
}
|
|
2820
2692
|
}
|
|
2821
2693
|
|
|
2822
2694
|
// src/commands/check.ts
|
|
2823
2695
|
init_esm_shims();
|
|
2824
2696
|
init_config();
|
|
2825
|
-
import { Command as
|
|
2826
|
-
import
|
|
2697
|
+
import { Command as Command9 } from "commander";
|
|
2698
|
+
import chalk14 from "chalk";
|
|
2827
2699
|
import ora7 from "ora";
|
|
2828
2700
|
import axios10 from "axios";
|
|
2829
2701
|
import { glob as glob3 } from "glob";
|
|
2830
|
-
import
|
|
2831
|
-
import
|
|
2702
|
+
import fs13 from "fs/promises";
|
|
2703
|
+
import path14 from "path";
|
|
2832
2704
|
import { execSync as execSync2 } from "child_process";
|
|
2833
2705
|
|
|
2834
2706
|
// src/utils/rule-engine.ts
|
|
2835
2707
|
init_esm_shims();
|
|
2836
|
-
import
|
|
2837
|
-
import
|
|
2838
|
-
import
|
|
2708
|
+
import fs12 from "fs/promises";
|
|
2709
|
+
import path13 from "path";
|
|
2710
|
+
import chalk13 from "chalk";
|
|
2839
2711
|
async function checkFile(filePath, rules, rootPath) {
|
|
2840
2712
|
const violations = [];
|
|
2841
|
-
const relativePath =
|
|
2713
|
+
const relativePath = path13.relative(rootPath, filePath);
|
|
2842
2714
|
try {
|
|
2843
|
-
const content = await
|
|
2715
|
+
const content = await fs12.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 = path13.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" ? chalk13.red : v.severity === "warning" ? chalk13.yellow : chalk13.blue;
|
|
2866
|
+
const lineInfo = v.line ? chalk13.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(` ${chalk13.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 Command9("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 = ora7();
|
|
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(chalk14.red("\u274C No project context found."));
|
|
2916
|
+
console.log(chalk14.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(chalk14.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(chalk14.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(chalk14.red("Failed to fetch rules and no valid cache"));
|
|
2956
|
+
console.log(chalk14.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 = path14.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) => path14.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 ${chalk14.cyan(targetPath)}...`);
|
|
2977
|
+
const pattern = path14.join(scanPath, "**/*");
|
|
3106
2978
|
const allFiles = await glob3(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(chalk14.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}: ${path14.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" + chalk14.bold("\u{1F4CA} Summary"));
|
|
3013
|
+
console.log(chalk14.dim("\u2500".repeat(50)));
|
|
3014
|
+
console.log(`Files checked: ${chalk14.cyan(summary.totalFiles)}`);
|
|
3015
|
+
console.log(`Total violations: ${summary.totalViolations > 0 ? chalk14.red(summary.totalViolations) : chalk14.green(0)}`);
|
|
3144
3016
|
if (summary.totalViolations > 0) {
|
|
3145
|
-
console.log(` ${
|
|
3146
|
-
console.log(` ${
|
|
3147
|
-
console.log(` ${
|
|
3017
|
+
console.log(` ${chalk14.red("Critical:")} ${summary.criticalCount}`);
|
|
3018
|
+
console.log(` ${chalk14.yellow("Warning:")} ${summary.warningCount}`);
|
|
3019
|
+
console.log(` ${chalk14.blue("Info:")} ${summary.infoCount}`);
|
|
3148
3020
|
}
|
|
3149
|
-
console.log(
|
|
3021
|
+
console.log(chalk14.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(chalk14.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(chalk14.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(chalk14.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(chalk14.red("Check failed"));
|
|
3039
|
+
console.error(chalk14.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 = path14.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 = path14.join(process.cwd(), CACHE_FILE2);
|
|
3052
|
+
const content = await fs13.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 = path14.join(process.cwd(), ".rigstate");
|
|
3065
|
+
await fs13.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 fs13.writeFile(
|
|
3073
|
+
path14.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" + chalk14.bold("\u{1F50D} Violations Found"));
|
|
3096
|
+
console.log(chalk14.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_esm_shims();
|
|
3106
|
+
import { Command as Command10 } from "commander";
|
|
3107
|
+
import chalk15 from "chalk";
|
|
3108
|
+
import fs14 from "fs/promises";
|
|
3109
|
+
import path15 from "path";
|
|
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 Command10("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 = path15.join(process.cwd(), ".git");
|
|
3139
|
+
try {
|
|
3140
|
+
await fs14.access(gitDir);
|
|
3141
|
+
} catch {
|
|
3142
|
+
console.log(chalk15.red("\u274C Not a git repository."));
|
|
3143
|
+
console.log(chalk15.dim(' Initialize with "git init" first.'));
|
|
3144
|
+
process.exit(1);
|
|
3145
|
+
}
|
|
3146
|
+
const hooksDir = path15.join(gitDir, "hooks");
|
|
3147
|
+
await fs14.mkdir(hooksDir, { recursive: true });
|
|
3148
|
+
const preCommitPath = path15.join(hooksDir, "pre-commit");
|
|
3149
|
+
let existingContent = "";
|
|
3150
|
+
try {
|
|
3151
|
+
existingContent = await fs14.readFile(preCommitPath, "utf-8");
|
|
3152
|
+
if (existingContent.includes("rigstate")) {
|
|
3153
|
+
console.log(chalk15.yellow("\u26A0 Rigstate pre-commit hook already installed."));
|
|
3154
|
+
console.log(chalk15.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 fs14.writeFile(preCommitPath, combinedScript, { mode: 493 });
|
|
3166
|
+
console.log(chalk15.green("\u2705 Rigstate hook appended to existing pre-commit."));
|
|
3167
|
+
} else {
|
|
3168
|
+
await fs14.writeFile(preCommitPath, script, { mode: 493 });
|
|
3169
|
+
console.log(chalk15.green("\u2705 Pre-commit hook installed!"));
|
|
3170
|
+
}
|
|
3171
|
+
console.log(chalk15.dim(` Path: ${preCommitPath}`));
|
|
3172
|
+
console.log(chalk15.dim(` Strict level: ${options.strict}`));
|
|
3173
|
+
console.log("");
|
|
3174
|
+
console.log(chalk15.cyan("Guardian will now check your code before each commit."));
|
|
3175
|
+
console.log(chalk15.dim('Use "rigstate hooks uninstall" to remove the hook.'));
|
|
3176
|
+
} catch (error) {
|
|
3177
|
+
console.error(chalk15.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 = path15.join(process.cwd(), ".git", "hooks", "pre-commit");
|
|
3184
|
+
try {
|
|
3185
|
+
const content = await fs14.readFile(preCommitPath, "utf-8");
|
|
3186
|
+
if (!content.includes("rigstate")) {
|
|
3187
|
+
console.log(chalk15.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 fs14.unlink(preCommitPath);
|
|
3192
|
+
console.log(chalk15.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 fs14.writeFile(preCommitPath, filteredLines.join("\n"), { mode: 493 });
|
|
3211
|
+
console.log(chalk15.green("\u2705 Rigstate section removed from pre-commit hook."));
|
|
3212
|
+
}
|
|
3213
|
+
} catch {
|
|
3214
|
+
console.log(chalk15.yellow("\u26A0 No pre-commit hook found."));
|
|
3215
|
+
}
|
|
3216
|
+
} catch (error) {
|
|
3217
|
+
console.error(chalk15.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_esm_shims();
|
|
3237
3226
|
import { Command as Command11 } from "commander";
|
|
3238
|
-
import
|
|
3227
|
+
import chalk20 from "chalk";
|
|
3239
3228
|
import ora8 from "ora";
|
|
3240
3229
|
import fs18 from "fs/promises";
|
|
3241
3230
|
import path20 from "path";
|
|
@@ -3247,7 +3236,7 @@ init_esm_shims();
|
|
|
3247
3236
|
|
|
3248
3237
|
// src/daemon/core.ts
|
|
3249
3238
|
init_esm_shims();
|
|
3250
|
-
import
|
|
3239
|
+
import chalk19 from "chalk";
|
|
3251
3240
|
import * as fs17 from "fs/promises";
|
|
3252
3241
|
import { EventEmitter as EventEmitter3 } from "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_esm_shims();
|
|
3805
|
+
import chalk18 from "chalk";
|
|
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 = chalk18.blue(`[${"INFO" /* INFO */}]`);
|
|
3813
|
+
break;
|
|
3814
|
+
case "WARN" /* WARN */:
|
|
3815
|
+
prefix = chalk18.yellow(`[${"WARN" /* WARN */}]`);
|
|
3816
|
+
break;
|
|
3817
|
+
case "ERROR" /* ERROR */:
|
|
3818
|
+
prefix = chalk18.red(`[${"ERROR" /* ERROR */}]`);
|
|
3819
|
+
break;
|
|
3820
|
+
case "DEBUG" /* DEBUG */:
|
|
3821
|
+
prefix = chalk18.gray(`[${"DEBUG" /* DEBUG */}]`);
|
|
3822
|
+
break;
|
|
3823
|
+
}
|
|
3824
|
+
let output = `${chalk18.gray(timestamp)} ${prefix} ${message}`;
|
|
3825
|
+
if (context) {
|
|
3826
|
+
if (context instanceof Error) {
|
|
3827
|
+
output += `
|
|
3828
|
+
${chalk18.red(context.stack || context.message)}`;
|
|
3829
|
+
} else if (typeof context === "object") {
|
|
3830
|
+
try {
|
|
3831
|
+
output += `
|
|
3832
|
+
${chalk18.gray(JSON.stringify(context, null, 2))}`;
|
|
3833
|
+
} catch (e) {
|
|
3834
|
+
output += `
|
|
3835
|
+
${chalk18.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 EventEmitter3 {
|
|
3814
3861
|
config;
|
|
3815
3862
|
state;
|
|
@@ -3832,7 +3879,7 @@ var GuardianDaemon = class extends EventEmitter3 {
|
|
|
3832
3879
|
}
|
|
3833
3880
|
async start() {
|
|
3834
3881
|
if (this.state.isRunning) {
|
|
3835
|
-
console.log(
|
|
3882
|
+
console.log(chalk19.yellow("Daemon is already running."));
|
|
3836
3883
|
return;
|
|
3837
3884
|
}
|
|
3838
3885
|
this.printWelcome();
|
|
@@ -3842,8 +3889,8 @@ var GuardianDaemon = class extends EventEmitter3 {
|
|
|
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 EventEmitter3 {
|
|
|
3853
3900
|
try {
|
|
3854
3901
|
await this.setupBridge();
|
|
3855
3902
|
} catch (e) {
|
|
3856
|
-
console.error(
|
|
3857
|
-
console.log(
|
|
3903
|
+
console.error(chalk19.yellow(` \u26A0\uFE0F Agent Bridge connection failed: ${e.message}`));
|
|
3904
|
+
console.log(chalk19.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(chalk19.bold.blue("\n\u{1F6E1}\uFE0F Guardian Daemon Starting..."));
|
|
3912
|
+
console.log(chalk19.dim(`Project: ${this.config.projectId}`));
|
|
3913
|
+
console.log(chalk19.dim(`API URL: ${this.config.apiUrl}`));
|
|
3914
|
+
console.log(chalk19.dim(`Watch Path: ${this.config.watchPath}`));
|
|
3915
|
+
console.log(chalk19.dim("\u2500".repeat(50)));
|
|
3869
3916
|
}
|
|
3870
3917
|
printActive() {
|
|
3871
|
-
console.log(
|
|
3872
|
-
console.log(
|
|
3873
|
-
console.log(
|
|
3918
|
+
console.log(chalk19.dim("\u2500".repeat(50)));
|
|
3919
|
+
console.log(chalk19.green.bold("\u2705 Guardian Daemon is now active"));
|
|
3920
|
+
console.log(chalk19.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", (path25) => this.handleFileChange(path25));
|
|
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" ? chalk18.red : v.severity === "warning" ? chalk18.yellow : chalk18.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(chalk19.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(chalk19.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(chalk19.green(" \u2713 Agent Bridge connected"));
|
|
3942
3998
|
}
|
|
3943
3999
|
async stop() {
|
|
3944
4000
|
if (!this.state.isRunning) return;
|
|
3945
|
-
console.log(
|
|
4001
|
+
console.log(chalk19.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(chalk19.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(chalk20.yellow("\u26A0 Another daemon instance is active (PID " + pid + ")."));
|
|
4069
|
+
console.log(chalk20.dim(` Run "rigstate daemon status" for details or Ctrl+C to stop.
|
|
4014
4070
|
`));
|
|
4015
4071
|
} catch {
|
|
4016
4072
|
await fs18.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(chalk20.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(chalk20.red("Failed to start daemon"));
|
|
4108
|
+
console.error(chalk20.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(chalk20.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(chalk20.yellow("Status: Not running"));
|
|
4161
|
+
console.log(chalk20.dim('Use "rigstate daemon" to start.\n'));
|
|
4106
4162
|
return;
|
|
4107
4163
|
}
|
|
4108
|
-
console.log(
|
|
4164
|
+
console.log(chalk20.green("Status: Running"));
|
|
4109
4165
|
try {
|
|
4110
4166
|
const statePath = path20.join(process.cwd(), STATE_FILE);
|
|
4111
4167
|
const content = await fs18.readFile(statePath, "utf-8");
|
|
4112
4168
|
const state = JSON.parse(content);
|
|
4113
|
-
console.log(
|
|
4169
|
+
console.log(chalk20.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(chalk20.dim("\u2500".repeat(40)));
|
|
4120
4176
|
} catch {
|
|
4121
|
-
console.log(
|
|
4177
|
+
console.log(chalk20.dim("(State file not found)"));
|
|
4122
4178
|
}
|
|
4123
4179
|
try {
|
|
4124
4180
|
const pidPath = path20.join(process.cwd(), PID_FILE);
|
|
4125
4181
|
const pid = await fs18.readFile(pidPath, "utf-8");
|
|
4126
|
-
console.log(
|
|
4182
|
+
console.log(chalk20.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(chalk20.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(chalk20.red("\u274C Currently only macOS is supported for auto-start."));
|
|
4191
|
+
console.error(chalk20.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(chalk20.red("\u274C Could not determine HOME directory."));
|
|
4141
4197
|
return;
|
|
4142
4198
|
}
|
|
4143
4199
|
const agentsDir = path20.join(homeDir, "Library/LaunchAgents");
|
|
@@ -4179,32 +4235,32 @@ async function enableDaemon() {
|
|
|
4179
4235
|
</plist>`;
|
|
4180
4236
|
try {
|
|
4181
4237
|
await fs18.writeFile(plistPath, plistContent);
|
|
4182
|
-
console.log(
|
|
4238
|
+
console.log(chalk20.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(chalk20.green("\u2705 Successfully enabled background daemon!"));
|
|
4245
|
+
console.log(chalk20.dim(`Logs: ${logDir}`));
|
|
4246
|
+
console.log(chalk20.dim("The daemon will now restart automatically if it crashes or on reboot."));
|
|
4191
4247
|
} catch (error) {
|
|
4192
|
-
console.error(
|
|
4248
|
+
console.error(chalk20.red("\u274C Failed to enable daemon:"), error.message);
|
|
4193
4249
|
}
|
|
4194
4250
|
}
|
|
4195
4251
|
async function disableDaemon() {
|
|
4196
|
-
console.log(
|
|
4252
|
+
console.log(chalk20.bold("\n\u2699\uFE0F Disabling Rigstate Background Service\n"));
|
|
4197
4253
|
const homeDir = process.env.HOME || "";
|
|
4198
4254
|
const plistPath = path20.join(homeDir, "Library/LaunchAgents/com.rigstate.daemon.plist");
|
|
4199
4255
|
try {
|
|
4200
4256
|
await execShellCommand(`launchctl unload ${plistPath}`);
|
|
4201
4257
|
await fs18.unlink(plistPath);
|
|
4202
|
-
console.log(
|
|
4258
|
+
console.log(chalk20.green("\u2705 Successfully disabled background daemon."));
|
|
4203
4259
|
} catch (error) {
|
|
4204
4260
|
if (error.code === "ENOENT") {
|
|
4205
|
-
console.log(
|
|
4261
|
+
console.log(chalk20.green("\u2705 Daemon was not enabled."));
|
|
4206
4262
|
} else {
|
|
4207
|
-
console.error(
|
|
4263
|
+
console.error(chalk20.red("\u274C Failed to disable daemon:"), error.message);
|
|
4208
4264
|
}
|
|
4209
4265
|
}
|
|
4210
4266
|
}
|
|
@@ -4222,7 +4278,7 @@ init_esm_shims();
|
|
|
4222
4278
|
init_config();
|
|
4223
4279
|
init_suggest();
|
|
4224
4280
|
import { Command as Command12 } from "commander";
|
|
4225
|
-
import
|
|
4281
|
+
import chalk21 from "chalk";
|
|
4226
4282
|
import ora9 from "ora";
|
|
4227
4283
|
import axios15 from "axios";
|
|
4228
4284
|
import inquirer2 from "inquirer";
|
|
@@ -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(chalk21.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} ${chalk21.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(chalk21.green(`Task updated to ${status}.`));
|
|
4313
4369
|
if (status === "IN_PROGRESS") {
|
|
4314
|
-
console.log(
|
|
4370
|
+
console.log(chalk21.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(chalk21.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(chalk21.bold.yellow("\u{1F6E1}\uFE0F FRANK'S QUALITY GATE"));
|
|
4380
|
+
console.log(chalk21.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 = ora9(" 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(chalk21.bold.green("\u{1F389} TASK COMPLETE! Momentum Preserved."));
|
|
4331
4387
|
const { projectId, apiKey, apiUrl } = getContext();
|
|
4332
4388
|
await suggestNextMove(projectId, apiKey, apiUrl);
|
|
4333
4389
|
}
|
|
@@ -4345,7 +4401,7 @@ function getContext() {
|
|
|
4345
4401
|
init_esm_shims();
|
|
4346
4402
|
init_config();
|
|
4347
4403
|
import { Command as Command13 } from "commander";
|
|
4348
|
-
import
|
|
4404
|
+
import chalk22 from "chalk";
|
|
4349
4405
|
import ora10 from "ora";
|
|
4350
4406
|
import chokidar2 from "chokidar";
|
|
4351
4407
|
import fs19 from "fs/promises";
|
|
@@ -4355,15 +4411,15 @@ import axios16 from "axios";
|
|
|
4355
4411
|
function createWatchCommand() {
|
|
4356
4412
|
const watch2 = new Command13("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(chalk22.bold.blue("\u{1F52D} Rigstate Watch Mode"));
|
|
4415
|
+
console.log(chalk22.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(chalk22.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(chalk22.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(chalk22.dim(`Auto-commit: ${config2.autoCommit ? "ON" : "OFF"}`));
|
|
4447
|
+
console.log(chalk22.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(chalk22.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(chalk22.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(chalk22.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(chalk22.bold.yellow(`\u{1F4CC} Active Task #${task.step_number}: ${task.title}`));
|
|
4559
|
+
console.log(chalk22.dim(`Status: ${task.status}`));
|
|
4504
4560
|
if (task.verification_criteria) {
|
|
4505
|
-
console.log(
|
|
4561
|
+
console.log(chalk22.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(chalk22.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(chalk22.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(chalk22.dim("Watch mode stopped."));
|
|
4548
4604
|
watcher.close();
|
|
4549
4605
|
process.exit(0);
|
|
4550
4606
|
});
|
|
@@ -4556,7 +4612,7 @@ function createWatchCommand() {
|
|
|
4556
4612
|
init_esm_shims();
|
|
4557
4613
|
init_config();
|
|
4558
4614
|
import { Command as Command14 } from "commander";
|
|
4559
|
-
import
|
|
4615
|
+
import chalk23 from "chalk";
|
|
4560
4616
|
import ora11 from "ora";
|
|
4561
4617
|
import axios17 from "axios";
|
|
4562
4618
|
import { execSync as execSync5 } from "child_process";
|
|
@@ -4571,7 +4627,7 @@ function createFocusCommand() {
|
|
|
4571
4627
|
try {
|
|
4572
4628
|
apiKey = getApiKey();
|
|
4573
4629
|
} catch (e) {
|
|
4574
|
-
spinner.fail(
|
|
4630
|
+
spinner.fail(chalk23.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(chalk23.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(chalk23.bold.blue(`\u{1F4CC} Task #${nextTask.step_number || "?"}: ${nextTask.title}`));
|
|
4676
|
+
const statusColor = nextTask.status === "IN_PROGRESS" ? chalk23.yellow : nextTask.status === "ACTIVE" ? chalk23.green : chalk23.dim;
|
|
4677
|
+
console.log(chalk23.dim("Status: ") + statusColor(nextTask.status));
|
|
4678
|
+
console.log(chalk23.dim("\u2500".repeat(60)));
|
|
4623
4679
|
if (nextTask.prompt_content) {
|
|
4624
|
-
console.log(
|
|
4625
|
-
console.log(
|
|
4680
|
+
console.log(chalk23.white(nextTask.prompt_content));
|
|
4681
|
+
console.log(chalk23.dim("\u2500".repeat(60)));
|
|
4626
4682
|
if (options.copy !== false) {
|
|
4627
4683
|
try {
|
|
4628
4684
|
if (process.platform === "darwin") {
|
|
4629
4685
|
execSync5("pbcopy", { input: nextTask.prompt_content });
|
|
4630
|
-
console.log(
|
|
4686
|
+
console.log(chalk23.green("\u2705 Prompt copied to clipboard! Ready to paste (Cmd+V)."));
|
|
4631
4687
|
} else if (process.platform === "linux") {
|
|
4632
4688
|
try {
|
|
4633
4689
|
execSync5("xclip -selection clipboard", { input: nextTask.prompt_content });
|
|
4634
|
-
console.log(
|
|
4690
|
+
console.log(chalk23.green("\u2705 Prompt copied to clipboard!"));
|
|
4635
4691
|
} catch (e) {
|
|
4636
|
-
console.log(
|
|
4692
|
+
console.log(chalk23.yellow("\u2139\uFE0F Copy prompt manually (xclip not available)"));
|
|
4637
4693
|
}
|
|
4638
4694
|
} else {
|
|
4639
|
-
console.log(
|
|
4695
|
+
console.log(chalk23.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(chalk23.yellow("No prompt instructions available."));
|
|
4646
4702
|
if (nextTask.architectural_brief) {
|
|
4647
|
-
console.log(
|
|
4703
|
+
console.log(chalk23.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(chalk23.red(`Failed to fetch task: ${e.message}`));
|
|
4654
4710
|
}
|
|
4655
4711
|
});
|
|
4656
4712
|
return focus;
|
|
@@ -4663,25 +4719,25 @@ init_env();
|
|
|
4663
4719
|
init_esm_shims();
|
|
4664
4720
|
init_config();
|
|
4665
4721
|
import { Command as Command15 } from "commander";
|
|
4666
|
-
import
|
|
4722
|
+
import chalk24 from "chalk";
|
|
4667
4723
|
function createConfigCommand() {
|
|
4668
4724
|
const config2 = new Command15("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(chalk24.bold("Rigstate Configuration"));
|
|
4728
|
+
console.log(chalk24.dim("\u2500".repeat(40)));
|
|
4673
4729
|
try {
|
|
4674
4730
|
const apiKey = getApiKey();
|
|
4675
|
-
console.log(`${
|
|
4731
|
+
console.log(`${chalk24.cyan("api_key")}: ${apiKey.substring(0, 20)}...`);
|
|
4676
4732
|
} catch (e) {
|
|
4677
|
-
console.log(`${
|
|
4733
|
+
console.log(`${chalk24.cyan("api_key")}: ${chalk24.dim("(not set)")}`);
|
|
4678
4734
|
}
|
|
4679
4735
|
const projectId = getProjectId();
|
|
4680
|
-
console.log(`${
|
|
4736
|
+
console.log(`${chalk24.cyan("project_id")}: ${projectId || chalk24.dim("(not set)")}`);
|
|
4681
4737
|
const apiUrl = getApiUrl();
|
|
4682
|
-
console.log(`${
|
|
4738
|
+
console.log(`${chalk24.cyan("api_url")}: ${apiUrl}`);
|
|
4683
4739
|
console.log("");
|
|
4684
|
-
console.log(
|
|
4740
|
+
console.log(chalk24.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(chalk24.dim("(not set)"));
|
|
4695
4751
|
}
|
|
4696
4752
|
break;
|
|
4697
4753
|
case "project_id":
|
|
4698
|
-
console.log(getProjectId() ||
|
|
4754
|
+
console.log(getProjectId() || chalk24.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(chalk24.red(`Unknown config key: ${key}`));
|
|
4761
|
+
console.log(chalk24.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(chalk24.green(`\u2705 api_key updated`));
|
|
4713
4769
|
break;
|
|
4714
4770
|
case "project_id":
|
|
4715
4771
|
setProjectId(value);
|
|
4716
|
-
console.log(
|
|
4772
|
+
console.log(chalk24.green(`\u2705 project_id updated`));
|
|
4717
4773
|
break;
|
|
4718
4774
|
case "api_url":
|
|
4719
4775
|
setApiUrl(value);
|
|
4720
|
-
console.log(
|
|
4776
|
+
console.log(chalk24.green(`\u2705 api_url updated`));
|
|
4721
4777
|
break;
|
|
4722
4778
|
default:
|
|
4723
|
-
console.log(
|
|
4724
|
-
console.log(
|
|
4779
|
+
console.log(chalk24.red(`Unknown config key: ${key}`));
|
|
4780
|
+
console.log(chalk24.dim("Valid keys: api_key, project_id, api_url"));
|
|
4725
4781
|
}
|
|
4726
4782
|
});
|
|
4727
4783
|
return config2;
|
|
@@ -4729,8 +4785,9 @@ function createConfigCommand() {
|
|
|
4729
4785
|
|
|
4730
4786
|
// src/commands/mcp.ts
|
|
4731
4787
|
init_esm_shims();
|
|
4788
|
+
init_config();
|
|
4732
4789
|
import { Command as Command16 } from "commander";
|
|
4733
|
-
import
|
|
4790
|
+
import chalk25 from "chalk";
|
|
4734
4791
|
import { spawn } from "child_process";
|
|
4735
4792
|
import path23 from "path";
|
|
4736
4793
|
import fs21 from "fs";
|
|
@@ -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(chalk25.red("\u274C Error: Rigstate MCP Server binary not found."));
|
|
4817
|
+
console.error(chalk25.yellow("Please ensure that the mcp package is built:"));
|
|
4818
|
+
console.error(chalk25.white(" cd packages/mcp && npm run build"));
|
|
4762
4819
|
console.error("");
|
|
4763
|
-
console.error(
|
|
4764
|
-
console.error(
|
|
4820
|
+
console.error(chalk25.dim("Or run directly with:"));
|
|
4821
|
+
console.error(chalk25.white(" npx @rigstate/mcp"));
|
|
4765
4822
|
process.exit(1);
|
|
4766
4823
|
}
|
|
4767
|
-
console.log(
|
|
4768
|
-
|
|
4769
|
-
|
|
4824
|
+
console.log(chalk25.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 = 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(chalk25.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
|
-
import
|
|
4926
|
+
import chalk26 from "chalk";
|
|
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(chalk26.dim("\u26A0\uFE0F Hive Gateway disabled (No Token provided). Running in localized mode."));
|
|
4870
4937
|
}
|
|
4871
4938
|
this.client = axios18.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(chalk26.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(chalk26.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(chalk26.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(chalk26.green("\u2705 Signal Received by Hive Core. Knowledge Shared."));
|
|
4903
4970
|
return true;
|
|
4904
4971
|
} catch (error) {
|
|
4905
|
-
console.error(
|
|
4972
|
+
console.error(chalk26.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_esm_shims();
|
|
4913
|
-
import chalk26 from "chalk";
|
|
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 = chalk26.blue(`[${"INFO" /* INFO */}]`);
|
|
4921
|
-
break;
|
|
4922
|
-
case "WARN" /* WARN */:
|
|
4923
|
-
prefix = chalk26.yellow(`[${"WARN" /* WARN */}]`);
|
|
4924
|
-
break;
|
|
4925
|
-
case "ERROR" /* ERROR */:
|
|
4926
|
-
prefix = chalk26.red(`[${"ERROR" /* ERROR */}]`);
|
|
4927
|
-
break;
|
|
4928
|
-
case "DEBUG" /* DEBUG */:
|
|
4929
|
-
prefix = chalk26.gray(`[${"DEBUG" /* DEBUG */}]`);
|
|
4930
|
-
break;
|
|
4931
|
-
}
|
|
4932
|
-
let output = `${chalk26.gray(timestamp)} ${prefix} ${message}`;
|
|
4933
|
-
if (context) {
|
|
4934
|
-
if (context instanceof Error) {
|
|
4935
|
-
output += `
|
|
4936
|
-
${chalk26.red(context.stack || context.message)}`;
|
|
4937
|
-
} else if (typeof context === "object") {
|
|
4938
|
-
try {
|
|
4939
|
-
output += `
|
|
4940
|
-
${chalk26.gray(JSON.stringify(context, null, 2))}`;
|
|
4941
|
-
} catch (e) {
|
|
4942
|
-
output += `
|
|
4943
|
-
${chalk26.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 EventEmitter4 {
|
|
4969
4980
|
context;
|