@rigstate/cli 0.7.22 → 0.7.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +535 -507
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +532 -504
- 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 +30 -0
- package/.rigstate/daemon.pid +0 -1
package/dist/index.js
CHANGED
|
@@ -287,10 +287,10 @@ async function syncProjectRules(projectId, apiKey, apiUrl, dryRun = false) {
|
|
|
287
287
|
const files = syncResponse.data.data.files;
|
|
288
288
|
if (files && Array.isArray(files)) {
|
|
289
289
|
const fs23 = await import("fs/promises");
|
|
290
|
-
const
|
|
290
|
+
const path26 = await import("path");
|
|
291
291
|
for (const file of files) {
|
|
292
|
-
const filePath =
|
|
293
|
-
await fs23.mkdir(
|
|
292
|
+
const filePath = path26.join(process.cwd(), file.path);
|
|
293
|
+
await fs23.mkdir(path26.dirname(filePath), { recursive: true });
|
|
294
294
|
await fs23.writeFile(filePath, file.content, "utf-8");
|
|
295
295
|
}
|
|
296
296
|
console.log(chalk3.dim(` \u{1F4BE} Wrote ${files.length} rule files to local .cursor/rules/`));
|
|
@@ -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
|
}
|
|
@@ -1663,10 +1533,10 @@ var require_src2 = __commonJS({
|
|
|
1663
1533
|
var fs_1 = __require("fs");
|
|
1664
1534
|
var debug_1 = __importDefault(require_src());
|
|
1665
1535
|
var log = debug_1.default("@kwsites/file-exists");
|
|
1666
|
-
function check(
|
|
1667
|
-
log(`checking %s`,
|
|
1536
|
+
function check(path26, isFile, isDirectory) {
|
|
1537
|
+
log(`checking %s`, path26);
|
|
1668
1538
|
try {
|
|
1669
|
-
const stat = fs_1.statSync(
|
|
1539
|
+
const stat = fs_1.statSync(path26);
|
|
1670
1540
|
if (stat.isFile() && isFile) {
|
|
1671
1541
|
log(`[OK] path represents a file`);
|
|
1672
1542
|
return true;
|
|
@@ -1686,8 +1556,8 @@ var require_src2 = __commonJS({
|
|
|
1686
1556
|
throw e;
|
|
1687
1557
|
}
|
|
1688
1558
|
}
|
|
1689
|
-
function exists2(
|
|
1690
|
-
return check(
|
|
1559
|
+
function exists2(path26, type = exports.READABLE) {
|
|
1560
|
+
return check(path26, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
|
|
1691
1561
|
}
|
|
1692
1562
|
exports.exists = exists2;
|
|
1693
1563
|
exports.FILE = 1;
|
|
@@ -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.24",
|
|
1761
1631
|
description: "Rigstate CLI - Code audit, sync and supervision tool",
|
|
1762
1632
|
type: "module",
|
|
1763
1633
|
main: "./dist/index.js",
|
|
@@ -1867,89 +1737,91 @@ 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
|
});
|
|
1934
1807
|
}
|
|
1935
1808
|
async function installHooks(cwd) {
|
|
1936
1809
|
const fs23 = await import("fs/promises");
|
|
1937
|
-
const
|
|
1810
|
+
const path26 = await import("path");
|
|
1938
1811
|
try {
|
|
1939
|
-
await fs23.access(
|
|
1812
|
+
await fs23.access(path26.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
|
-
const hooksDir =
|
|
1817
|
+
const hooksDir = path26.join(cwd, ".husky");
|
|
1945
1818
|
try {
|
|
1946
|
-
const
|
|
1947
|
-
const preCommitPath = path25.join(cwd, ".git/hooks/pre-commit");
|
|
1819
|
+
const preCommitPath = path26.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,8 +3101,125 @@ 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();
|
|
@@ -3238,7 +3227,7 @@ import { Command as Command11 } from "commander";
|
|
|
3238
3227
|
import chalk20 from "chalk";
|
|
3239
3228
|
import ora8 from "ora";
|
|
3240
3229
|
import fs18 from "fs/promises";
|
|
3241
|
-
import
|
|
3230
|
+
import path21 from "path";
|
|
3242
3231
|
import { execSync as execSync3 } from "child_process";
|
|
3243
3232
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3244
3233
|
|
|
@@ -3249,6 +3238,7 @@ init_esm_shims();
|
|
|
3249
3238
|
init_esm_shims();
|
|
3250
3239
|
import chalk19 from "chalk";
|
|
3251
3240
|
import * as fs17 from "fs/promises";
|
|
3241
|
+
import path20 from "path";
|
|
3252
3242
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
3253
3243
|
|
|
3254
3244
|
// src/daemon/file-watcher.ts
|
|
@@ -3916,6 +3906,7 @@ var GuardianDaemon = class extends EventEmitter3 {
|
|
|
3916
3906
|
}
|
|
3917
3907
|
}
|
|
3918
3908
|
this.printActive();
|
|
3909
|
+
await this.updateViolationReport([]);
|
|
3919
3910
|
this.emit("started", this.state);
|
|
3920
3911
|
}
|
|
3921
3912
|
printWelcome() {
|
|
@@ -3938,7 +3929,7 @@ var GuardianDaemon = class extends EventEmitter3 {
|
|
|
3938
3929
|
setupFileWatcher() {
|
|
3939
3930
|
Logger.info("Starting file watcher...");
|
|
3940
3931
|
this.fileWatcher = createFileWatcher(this.config.watchPath);
|
|
3941
|
-
this.fileWatcher.on("change", (
|
|
3932
|
+
this.fileWatcher.on("change", (path26) => this.handleFileChange(path26));
|
|
3942
3933
|
this.fileWatcher.start();
|
|
3943
3934
|
Logger.info("File watcher active");
|
|
3944
3935
|
}
|
|
@@ -3979,11 +3970,37 @@ var GuardianDaemon = class extends EventEmitter3 {
|
|
|
3979
3970
|
this.state.filesChecked++;
|
|
3980
3971
|
if (result.violations.length > 0) {
|
|
3981
3972
|
this.handleViolations(filePath, result.violations);
|
|
3973
|
+
} else {
|
|
3974
|
+
await this.updateViolationReport([]);
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
async updateViolationReport(violations) {
|
|
3978
|
+
const reportPath = path20.join(process.cwd(), ".rigstate", "ACTIVE_VIOLATIONS.md");
|
|
3979
|
+
let content = `# \u{1F6E1}\uFE0F Guardian Status: ${violations.length > 0 ? "\u26A0\uFE0F ATTENTION" : "\u2705 PASS"}
|
|
3980
|
+
|
|
3981
|
+
`;
|
|
3982
|
+
content += `*Last check: ${(/* @__PURE__ */ new Date()).toLocaleString()}*
|
|
3983
|
+
|
|
3984
|
+
`;
|
|
3985
|
+
if (violations.length === 0) {
|
|
3986
|
+
content += "All systems within architectural limits. Frank is satisfied. \u{1F92B}\n";
|
|
3987
|
+
} else {
|
|
3988
|
+
content += "### \u{1F6A8} Active Violations\n\n";
|
|
3989
|
+
for (const v of violations) {
|
|
3990
|
+
content += `- **[${v.severity.toUpperCase()}]**: ${v.message}
|
|
3991
|
+
`;
|
|
3992
|
+
}
|
|
3993
|
+
content += "\n---\n*Rigstate Daemon is watching. Fix violations to clear this report.*";
|
|
3994
|
+
}
|
|
3995
|
+
try {
|
|
3996
|
+
await fs17.writeFile(reportPath, content, "utf-8");
|
|
3997
|
+
} catch (e) {
|
|
3982
3998
|
}
|
|
3983
3999
|
}
|
|
3984
4000
|
handleViolations(filePath, violations) {
|
|
3985
4001
|
this.state.violationsFound += violations.length;
|
|
3986
4002
|
this.emit("violation", { file: filePath, violations });
|
|
4003
|
+
this.updateViolationReport(violations);
|
|
3987
4004
|
for (const v of violations) {
|
|
3988
4005
|
const level = v.severity === "critical" ? "error" : v.severity === "warning" ? "warn" : "info";
|
|
3989
4006
|
Logger[level](`[${v.severity.toUpperCase()}] ${filePath}: ${v.message}`);
|
|
@@ -4070,7 +4087,7 @@ function createDaemonCommand() {
|
|
|
4070
4087
|
}
|
|
4071
4088
|
const spinner = ora8();
|
|
4072
4089
|
try {
|
|
4073
|
-
const pidPath =
|
|
4090
|
+
const pidPath = path21.join(process.cwd(), PID_FILE);
|
|
4074
4091
|
try {
|
|
4075
4092
|
const content = await fs18.readFile(pidPath, "utf-8");
|
|
4076
4093
|
const pid = parseInt(content.trim(), 10);
|
|
@@ -4124,7 +4141,7 @@ function createDaemonCommand() {
|
|
|
4124
4141
|
}
|
|
4125
4142
|
async function isRunning() {
|
|
4126
4143
|
try {
|
|
4127
|
-
const pidPath =
|
|
4144
|
+
const pidPath = path21.join(process.cwd(), PID_FILE);
|
|
4128
4145
|
const content = await fs18.readFile(pidPath, "utf-8");
|
|
4129
4146
|
const pid = parseInt(content.trim(), 10);
|
|
4130
4147
|
try {
|
|
@@ -4140,25 +4157,25 @@ async function isRunning() {
|
|
|
4140
4157
|
}
|
|
4141
4158
|
async function writePidFile() {
|
|
4142
4159
|
try {
|
|
4143
|
-
const dir =
|
|
4160
|
+
const dir = path21.join(process.cwd(), ".rigstate");
|
|
4144
4161
|
await fs18.mkdir(dir, { recursive: true });
|
|
4145
|
-
await fs18.writeFile(
|
|
4162
|
+
await fs18.writeFile(path21.join(dir, "daemon.pid"), process.pid.toString());
|
|
4146
4163
|
} catch {
|
|
4147
4164
|
}
|
|
4148
4165
|
}
|
|
4149
4166
|
async function cleanupPidFile() {
|
|
4150
4167
|
try {
|
|
4151
|
-
await fs18.unlink(
|
|
4152
|
-
await fs18.unlink(
|
|
4168
|
+
await fs18.unlink(path21.join(process.cwd(), PID_FILE));
|
|
4169
|
+
await fs18.unlink(path21.join(process.cwd(), STATE_FILE));
|
|
4153
4170
|
} catch {
|
|
4154
4171
|
}
|
|
4155
4172
|
}
|
|
4156
4173
|
async function writeStateFile(state) {
|
|
4157
4174
|
try {
|
|
4158
|
-
const dir =
|
|
4175
|
+
const dir = path21.join(process.cwd(), ".rigstate");
|
|
4159
4176
|
await fs18.mkdir(dir, { recursive: true });
|
|
4160
4177
|
await fs18.writeFile(
|
|
4161
|
-
|
|
4178
|
+
path21.join(dir, "daemon.state.json"),
|
|
4162
4179
|
JSON.stringify(state, null, 2)
|
|
4163
4180
|
);
|
|
4164
4181
|
} catch {
|
|
@@ -4174,7 +4191,7 @@ async function showStatus() {
|
|
|
4174
4191
|
}
|
|
4175
4192
|
console.log(chalk20.green("Status: Running"));
|
|
4176
4193
|
try {
|
|
4177
|
-
const statePath =
|
|
4194
|
+
const statePath = path21.join(process.cwd(), STATE_FILE);
|
|
4178
4195
|
const content = await fs18.readFile(statePath, "utf-8");
|
|
4179
4196
|
const state = JSON.parse(content);
|
|
4180
4197
|
console.log(chalk20.dim("\u2500".repeat(40)));
|
|
@@ -4188,7 +4205,7 @@ async function showStatus() {
|
|
|
4188
4205
|
console.log(chalk20.dim("(State file not found)"));
|
|
4189
4206
|
}
|
|
4190
4207
|
try {
|
|
4191
|
-
const pidPath =
|
|
4208
|
+
const pidPath = path21.join(process.cwd(), PID_FILE);
|
|
4192
4209
|
const pid = await fs18.readFile(pidPath, "utf-8");
|
|
4193
4210
|
console.log(chalk20.dim(`PID: ${pid.trim()}`));
|
|
4194
4211
|
} catch {
|
|
@@ -4207,9 +4224,9 @@ async function enableDaemon() {
|
|
|
4207
4224
|
console.error(chalk20.red("\u274C Could not determine HOME directory."));
|
|
4208
4225
|
return;
|
|
4209
4226
|
}
|
|
4210
|
-
const agentsDir =
|
|
4211
|
-
const logDir =
|
|
4212
|
-
const plistPath =
|
|
4227
|
+
const agentsDir = path21.join(homeDir, "Library/LaunchAgents");
|
|
4228
|
+
const logDir = path21.join(homeDir, ".rigstate/logs");
|
|
4229
|
+
const plistPath = path21.join(agentsDir, "com.rigstate.daemon.plist");
|
|
4213
4230
|
await fs18.mkdir(agentsDir, { recursive: true });
|
|
4214
4231
|
await fs18.mkdir(logDir, { recursive: true });
|
|
4215
4232
|
const scriptPath = fileURLToPath2(import.meta.url);
|
|
@@ -4230,9 +4247,9 @@ async function enableDaemon() {
|
|
|
4230
4247
|
<key>WorkingDirectory</key>
|
|
4231
4248
|
<string>${process.cwd()}</string>
|
|
4232
4249
|
<key>StandardOutPath</key>
|
|
4233
|
-
<string>${
|
|
4250
|
+
<string>${path21.join(logDir, "daemon.out.log")}</string>
|
|
4234
4251
|
<key>StandardErrorPath</key>
|
|
4235
|
-
<string>${
|
|
4252
|
+
<string>${path21.join(logDir, "daemon.err.log")}</string>
|
|
4236
4253
|
<key>RunAtLoad</key>
|
|
4237
4254
|
<true/>
|
|
4238
4255
|
<key>KeepAlive</key>
|
|
@@ -4262,7 +4279,7 @@ async function enableDaemon() {
|
|
|
4262
4279
|
async function disableDaemon() {
|
|
4263
4280
|
console.log(chalk20.bold("\n\u2699\uFE0F Disabling Rigstate Background Service\n"));
|
|
4264
4281
|
const homeDir = process.env.HOME || "";
|
|
4265
|
-
const plistPath =
|
|
4282
|
+
const plistPath = path21.join(homeDir, "Library/LaunchAgents/com.rigstate.daemon.plist");
|
|
4266
4283
|
try {
|
|
4267
4284
|
await execShellCommand(`launchctl unload ${plistPath}`);
|
|
4268
4285
|
await fs18.unlink(plistPath);
|
|
@@ -4416,7 +4433,7 @@ import chalk22 from "chalk";
|
|
|
4416
4433
|
import ora10 from "ora";
|
|
4417
4434
|
import chokidar2 from "chokidar";
|
|
4418
4435
|
import fs19 from "fs/promises";
|
|
4419
|
-
import
|
|
4436
|
+
import path22 from "path";
|
|
4420
4437
|
import { execSync as execSync4 } from "child_process";
|
|
4421
4438
|
import axios16 from "axios";
|
|
4422
4439
|
function createWatchCommand() {
|
|
@@ -4436,7 +4453,7 @@ function createWatchCommand() {
|
|
|
4436
4453
|
projectId = getProjectId();
|
|
4437
4454
|
if (!projectId) {
|
|
4438
4455
|
try {
|
|
4439
|
-
const manifestPath =
|
|
4456
|
+
const manifestPath = path22.join(process.cwd(), ".rigstate");
|
|
4440
4457
|
const content = await fs19.readFile(manifestPath, "utf-8");
|
|
4441
4458
|
const manifest = JSON.parse(content);
|
|
4442
4459
|
projectId = manifest.project_id;
|
|
@@ -4483,7 +4500,7 @@ function createWatchCommand() {
|
|
|
4483
4500
|
};
|
|
4484
4501
|
const checkCriteria = async (criteria) => {
|
|
4485
4502
|
try {
|
|
4486
|
-
const fullPath =
|
|
4503
|
+
const fullPath = path22.resolve(process.cwd(), criteria.path);
|
|
4487
4504
|
switch (criteria.type) {
|
|
4488
4505
|
case "file_exists":
|
|
4489
4506
|
await fs19.access(fullPath);
|
|
@@ -4628,7 +4645,7 @@ import ora11 from "ora";
|
|
|
4628
4645
|
import axios17 from "axios";
|
|
4629
4646
|
import { execSync as execSync5 } from "child_process";
|
|
4630
4647
|
import fs20 from "fs/promises";
|
|
4631
|
-
import
|
|
4648
|
+
import path23 from "path";
|
|
4632
4649
|
function createFocusCommand() {
|
|
4633
4650
|
const focus = new Command14("focus");
|
|
4634
4651
|
focus.alias("task").description("Get the next active roadmap task and copy its prompt to clipboard").option("--no-copy", "Do not copy to clipboard").action(async (options) => {
|
|
@@ -4644,7 +4661,7 @@ function createFocusCommand() {
|
|
|
4644
4661
|
projectId = getProjectId();
|
|
4645
4662
|
if (!projectId) {
|
|
4646
4663
|
try {
|
|
4647
|
-
const manifestPath =
|
|
4664
|
+
const manifestPath = path23.join(process.cwd(), ".rigstate");
|
|
4648
4665
|
const content = await fs20.readFile(manifestPath, "utf-8");
|
|
4649
4666
|
const manifest = JSON.parse(content);
|
|
4650
4667
|
projectId = manifest.project_id;
|
|
@@ -4796,24 +4813,25 @@ function createConfigCommand() {
|
|
|
4796
4813
|
|
|
4797
4814
|
// src/commands/mcp.ts
|
|
4798
4815
|
init_esm_shims();
|
|
4816
|
+
init_config();
|
|
4799
4817
|
import { Command as Command16 } from "commander";
|
|
4800
4818
|
import chalk25 from "chalk";
|
|
4801
4819
|
import { spawn } from "child_process";
|
|
4802
|
-
import
|
|
4820
|
+
import path24 from "path";
|
|
4803
4821
|
import fs21 from "fs";
|
|
4804
4822
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
4805
4823
|
var __filename2 = fileURLToPath3(import.meta.url);
|
|
4806
|
-
var __dirname2 =
|
|
4824
|
+
var __dirname2 = path24.dirname(__filename2);
|
|
4807
4825
|
function createMcpCommand() {
|
|
4808
4826
|
const mcp = new Command16("mcp");
|
|
4809
4827
|
mcp.description("Run the Rigstate MCP server for AI editors").action(async () => {
|
|
4810
4828
|
const possiblePaths = [
|
|
4811
4829
|
// From packages/cli -> packages/mcp (sibling package)
|
|
4812
|
-
|
|
4830
|
+
path24.resolve(__dirname2, "../../mcp/dist/index.js"),
|
|
4813
4831
|
// If installed globally or via npm
|
|
4814
|
-
|
|
4832
|
+
path24.resolve(__dirname2, "../../../mcp/dist/index.js"),
|
|
4815
4833
|
// Development path from packages/cli/dist
|
|
4816
|
-
|
|
4834
|
+
path24.resolve(__dirname2, "../../../packages/mcp/dist/index.js")
|
|
4817
4835
|
];
|
|
4818
4836
|
let serverPath = "";
|
|
4819
4837
|
for (const p of possiblePaths) {
|
|
@@ -4832,11 +4850,21 @@ function createMcpCommand() {
|
|
|
4832
4850
|
process.exit(1);
|
|
4833
4851
|
}
|
|
4834
4852
|
console.log(chalk25.dim(`Starting MCP server from: ${serverPath}`));
|
|
4835
|
-
|
|
4836
|
-
|
|
4853
|
+
const env = { ...process.env };
|
|
4854
|
+
try {
|
|
4855
|
+
const apiKey = getApiKey();
|
|
4856
|
+
if (apiKey) {
|
|
4857
|
+
env.RIGSTATE_API_KEY = apiKey;
|
|
4858
|
+
env.RIGSTATE_APP_URL = getApiUrl();
|
|
4859
|
+
env.RIGSTATE_API_URL = getApiUrl();
|
|
4860
|
+
}
|
|
4861
|
+
} catch (e) {
|
|
4862
|
+
}
|
|
4863
|
+
if (env.VIBE_API_KEY && !env.RIGSTATE_API_KEY) {
|
|
4864
|
+
env.RIGSTATE_API_KEY = env.VIBE_API_KEY;
|
|
4837
4865
|
}
|
|
4838
4866
|
const worker = spawn("node", [serverPath], {
|
|
4839
|
-
env
|
|
4867
|
+
env,
|
|
4840
4868
|
stdio: ["inherit", "inherit", "inherit"]
|
|
4841
4869
|
});
|
|
4842
4870
|
worker.on("error", (err) => {
|
|
@@ -5247,7 +5275,7 @@ import chalk30 from "chalk";
|
|
|
5247
5275
|
import ora13 from "ora";
|
|
5248
5276
|
import inquirer5 from "inquirer";
|
|
5249
5277
|
import fs22 from "fs/promises";
|
|
5250
|
-
import
|
|
5278
|
+
import path25 from "path";
|
|
5251
5279
|
|
|
5252
5280
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
5253
5281
|
init_esm_shims();
|
|
@@ -5287,8 +5315,8 @@ function pathspec(...paths) {
|
|
|
5287
5315
|
cache.set(key, paths);
|
|
5288
5316
|
return key;
|
|
5289
5317
|
}
|
|
5290
|
-
function isPathSpec(
|
|
5291
|
-
return
|
|
5318
|
+
function isPathSpec(path26) {
|
|
5319
|
+
return path26 instanceof String && cache.has(path26);
|
|
5292
5320
|
}
|
|
5293
5321
|
function toPaths(pathSpec) {
|
|
5294
5322
|
return cache.get(pathSpec) || [];
|
|
@@ -5377,8 +5405,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
5377
5405
|
function forEachLineWithContent(input, callback) {
|
|
5378
5406
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
5379
5407
|
}
|
|
5380
|
-
function folderExists(
|
|
5381
|
-
return (0, import_file_exists.exists)(
|
|
5408
|
+
function folderExists(path26) {
|
|
5409
|
+
return (0, import_file_exists.exists)(path26, import_file_exists.FOLDER);
|
|
5382
5410
|
}
|
|
5383
5411
|
function append(target, item) {
|
|
5384
5412
|
if (Array.isArray(target)) {
|
|
@@ -5782,8 +5810,8 @@ function checkIsRepoRootTask() {
|
|
|
5782
5810
|
commands,
|
|
5783
5811
|
format: "utf-8",
|
|
5784
5812
|
onError,
|
|
5785
|
-
parser(
|
|
5786
|
-
return /^\.(git)?$/.test(
|
|
5813
|
+
parser(path26) {
|
|
5814
|
+
return /^\.(git)?$/.test(path26.trim());
|
|
5787
5815
|
}
|
|
5788
5816
|
};
|
|
5789
5817
|
}
|
|
@@ -6217,11 +6245,11 @@ function parseGrep(grep) {
|
|
|
6217
6245
|
const paths = /* @__PURE__ */ new Set();
|
|
6218
6246
|
const results = {};
|
|
6219
6247
|
forEachLineWithContent(grep, (input) => {
|
|
6220
|
-
const [
|
|
6221
|
-
paths.add(
|
|
6222
|
-
(results[
|
|
6248
|
+
const [path26, line, preview] = input.split(NULL);
|
|
6249
|
+
paths.add(path26);
|
|
6250
|
+
(results[path26] = results[path26] || []).push({
|
|
6223
6251
|
line: asNumber(line),
|
|
6224
|
-
path:
|
|
6252
|
+
path: path26,
|
|
6225
6253
|
preview
|
|
6226
6254
|
});
|
|
6227
6255
|
});
|
|
@@ -6986,14 +7014,14 @@ var init_hash_object = __esm2({
|
|
|
6986
7014
|
init_task();
|
|
6987
7015
|
}
|
|
6988
7016
|
});
|
|
6989
|
-
function parseInit(bare,
|
|
7017
|
+
function parseInit(bare, path26, text) {
|
|
6990
7018
|
const response = String(text).trim();
|
|
6991
7019
|
let result;
|
|
6992
7020
|
if (result = initResponseRegex.exec(response)) {
|
|
6993
|
-
return new InitSummary(bare,
|
|
7021
|
+
return new InitSummary(bare, path26, false, result[1]);
|
|
6994
7022
|
}
|
|
6995
7023
|
if (result = reInitResponseRegex.exec(response)) {
|
|
6996
|
-
return new InitSummary(bare,
|
|
7024
|
+
return new InitSummary(bare, path26, true, result[1]);
|
|
6997
7025
|
}
|
|
6998
7026
|
let gitDir = "";
|
|
6999
7027
|
const tokens = response.split(" ");
|
|
@@ -7004,7 +7032,7 @@ function parseInit(bare, path25, text) {
|
|
|
7004
7032
|
break;
|
|
7005
7033
|
}
|
|
7006
7034
|
}
|
|
7007
|
-
return new InitSummary(bare,
|
|
7035
|
+
return new InitSummary(bare, path26, /^re/i.test(response), gitDir);
|
|
7008
7036
|
}
|
|
7009
7037
|
var InitSummary;
|
|
7010
7038
|
var initResponseRegex;
|
|
@@ -7013,9 +7041,9 @@ var init_InitSummary = __esm2({
|
|
|
7013
7041
|
"src/lib/responses/InitSummary.ts"() {
|
|
7014
7042
|
"use strict";
|
|
7015
7043
|
InitSummary = class {
|
|
7016
|
-
constructor(bare,
|
|
7044
|
+
constructor(bare, path26, existing, gitDir) {
|
|
7017
7045
|
this.bare = bare;
|
|
7018
|
-
this.path =
|
|
7046
|
+
this.path = path26;
|
|
7019
7047
|
this.existing = existing;
|
|
7020
7048
|
this.gitDir = gitDir;
|
|
7021
7049
|
}
|
|
@@ -7027,7 +7055,7 @@ var init_InitSummary = __esm2({
|
|
|
7027
7055
|
function hasBareCommand(command) {
|
|
7028
7056
|
return command.includes(bareCommand);
|
|
7029
7057
|
}
|
|
7030
|
-
function initTask(bare = false,
|
|
7058
|
+
function initTask(bare = false, path26, customArgs) {
|
|
7031
7059
|
const commands = ["init", ...customArgs];
|
|
7032
7060
|
if (bare && !hasBareCommand(commands)) {
|
|
7033
7061
|
commands.splice(1, 0, bareCommand);
|
|
@@ -7036,7 +7064,7 @@ function initTask(bare = false, path25, customArgs) {
|
|
|
7036
7064
|
commands,
|
|
7037
7065
|
format: "utf-8",
|
|
7038
7066
|
parser(text) {
|
|
7039
|
-
return parseInit(commands.includes("--bare"),
|
|
7067
|
+
return parseInit(commands.includes("--bare"), path26, text);
|
|
7040
7068
|
}
|
|
7041
7069
|
};
|
|
7042
7070
|
}
|
|
@@ -7852,12 +7880,12 @@ var init_FileStatusSummary = __esm2({
|
|
|
7852
7880
|
"use strict";
|
|
7853
7881
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
7854
7882
|
FileStatusSummary = class {
|
|
7855
|
-
constructor(
|
|
7856
|
-
this.path =
|
|
7883
|
+
constructor(path26, index, working_dir) {
|
|
7884
|
+
this.path = path26;
|
|
7857
7885
|
this.index = index;
|
|
7858
7886
|
this.working_dir = working_dir;
|
|
7859
7887
|
if (index === "R" || working_dir === "R") {
|
|
7860
|
-
const detail = fromPathRegex.exec(
|
|
7888
|
+
const detail = fromPathRegex.exec(path26) || [null, path26, path26];
|
|
7861
7889
|
this.from = detail[2] || "";
|
|
7862
7890
|
this.path = detail[1] || "";
|
|
7863
7891
|
}
|
|
@@ -7888,14 +7916,14 @@ function splitLine(result, lineStr) {
|
|
|
7888
7916
|
default:
|
|
7889
7917
|
return;
|
|
7890
7918
|
}
|
|
7891
|
-
function data(index, workingDir,
|
|
7919
|
+
function data(index, workingDir, path26) {
|
|
7892
7920
|
const raw = `${index}${workingDir}`;
|
|
7893
7921
|
const handler = parsers6.get(raw);
|
|
7894
7922
|
if (handler) {
|
|
7895
|
-
handler(result,
|
|
7923
|
+
handler(result, path26);
|
|
7896
7924
|
}
|
|
7897
7925
|
if (raw !== "##" && raw !== "!!") {
|
|
7898
|
-
result.files.push(new FileStatusSummary(
|
|
7926
|
+
result.files.push(new FileStatusSummary(path26, index, workingDir));
|
|
7899
7927
|
}
|
|
7900
7928
|
}
|
|
7901
7929
|
}
|
|
@@ -8208,9 +8236,9 @@ var init_simple_git_api = __esm2({
|
|
|
8208
8236
|
next
|
|
8209
8237
|
);
|
|
8210
8238
|
}
|
|
8211
|
-
hashObject(
|
|
8239
|
+
hashObject(path26, write) {
|
|
8212
8240
|
return this._runTask(
|
|
8213
|
-
hashObjectTask(
|
|
8241
|
+
hashObjectTask(path26, write === true),
|
|
8214
8242
|
trailingFunctionArgument(arguments)
|
|
8215
8243
|
);
|
|
8216
8244
|
}
|
|
@@ -8563,8 +8591,8 @@ var init_branch = __esm2({
|
|
|
8563
8591
|
}
|
|
8564
8592
|
});
|
|
8565
8593
|
function toPath(input) {
|
|
8566
|
-
const
|
|
8567
|
-
return
|
|
8594
|
+
const path26 = input.trim().replace(/^["']|["']$/g, "");
|
|
8595
|
+
return path26 && normalize(path26);
|
|
8568
8596
|
}
|
|
8569
8597
|
var parseCheckIgnore;
|
|
8570
8598
|
var init_CheckIgnore = __esm2({
|
|
@@ -8878,8 +8906,8 @@ __export2(sub_module_exports, {
|
|
|
8878
8906
|
subModuleTask: () => subModuleTask,
|
|
8879
8907
|
updateSubModuleTask: () => updateSubModuleTask
|
|
8880
8908
|
});
|
|
8881
|
-
function addSubModuleTask(repo,
|
|
8882
|
-
return subModuleTask(["add", repo,
|
|
8909
|
+
function addSubModuleTask(repo, path26) {
|
|
8910
|
+
return subModuleTask(["add", repo, path26]);
|
|
8883
8911
|
}
|
|
8884
8912
|
function initSubModuleTask(customArgs) {
|
|
8885
8913
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -9209,8 +9237,8 @@ var require_git = __commonJS2({
|
|
|
9209
9237
|
}
|
|
9210
9238
|
return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
|
|
9211
9239
|
};
|
|
9212
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
9213
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
9240
|
+
Git2.prototype.submoduleAdd = function(repo, path26, then) {
|
|
9241
|
+
return this._runTask(addSubModuleTask2(repo, path26), trailingFunctionArgument2(arguments));
|
|
9214
9242
|
};
|
|
9215
9243
|
Git2.prototype.submoduleUpdate = function(args, then) {
|
|
9216
9244
|
return this._runTask(
|
|
@@ -9810,7 +9838,7 @@ function createReleaseCommand() {
|
|
|
9810
9838
|
return;
|
|
9811
9839
|
}
|
|
9812
9840
|
spinner.text = "Scanning completed tasks...";
|
|
9813
|
-
const pkgPath =
|
|
9841
|
+
const pkgPath = path25.resolve(process.cwd(), "package.json");
|
|
9814
9842
|
const pkgContent = await fs22.readFile(pkgPath, "utf-8");
|
|
9815
9843
|
const pkg2 = JSON.parse(pkgContent);
|
|
9816
9844
|
const currentVersion = pkg2.version;
|
|
@@ -9832,7 +9860,7 @@ function createReleaseCommand() {
|
|
|
9832
9860
|
}
|
|
9833
9861
|
pkg2.version = newVersion;
|
|
9834
9862
|
await fs22.writeFile(pkgPath, JSON.stringify(pkg2, null, 4));
|
|
9835
|
-
const changelogPath =
|
|
9863
|
+
const changelogPath = path25.resolve(process.cwd(), "CHANGELOG.md");
|
|
9836
9864
|
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
9837
9865
|
const entry = `
|
|
9838
9866
|
## [${newVersion}] - ${date}
|