rulecloud 0.1.0 → 0.1.1

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/autofix.js CHANGED
@@ -36,7 +36,16 @@ async function confirm(prompt) {
36
36
  });
37
37
  }
38
38
  export async function runAutofixForFile(opts) {
39
- requireApiKey(opts.cfg);
39
+ try {
40
+ requireApiKey(opts.cfg);
41
+ }
42
+ catch (err) {
43
+ const message = err instanceof Error ? err.message : "API key required";
44
+ console.log(opts.plain
45
+ ? `✖ Auto-fix unavailable: ${message}`
46
+ : pc.red(`✖ Auto-fix unavailable: ${message}`));
47
+ return false;
48
+ }
40
49
  const targets = opts.findings
41
50
  .filter((f) => f.file === opts.relPath)
42
51
  .sort((a, b) => {
@@ -48,21 +57,47 @@ export async function runAutofixForFile(opts) {
48
57
  return false;
49
58
  }
50
59
  const violation = targets[0];
51
- const { status, body } = await postAutofix(opts.cfg, {
52
- code: opts.code,
53
- violation: violation,
54
- rules_yaml: opts.rulesYaml,
55
- });
60
+ let status;
61
+ let body;
62
+ try {
63
+ ({ status, body } = await postAutofix(opts.cfg, {
64
+ code: opts.code,
65
+ violation: violation,
66
+ rules_yaml: opts.rulesYaml,
67
+ }));
68
+ }
69
+ catch (err) {
70
+ const message = err instanceof Error ? err.message : "Network error calling Auto-Fix API";
71
+ console.log(opts.plain
72
+ ? `✖ Auto-fix unavailable: ${message}`
73
+ : pc.red(`✖ Auto-fix unavailable: ${message}`));
74
+ return false;
75
+ }
56
76
  if (status === 402) {
57
77
  const msg = body.detail || "AI Auto-Fix requires RuleCloud Pro";
58
- console.log(opts.plain ? msg : pc.yellow(msg));
78
+ console.log(opts.plain
79
+ ? `✖ Auto-fix unavailable: ${msg}`
80
+ : pc.red(`✖ Auto-fix unavailable: ${msg}`));
59
81
  console.log(opts.plain
60
82
  ? "Upgrade: https://rulecloud.vercel.app/dashboard/billing"
61
83
  : pc.cyan("Upgrade: https://rulecloud.vercel.app/dashboard/billing"));
62
84
  return false;
63
85
  }
86
+ if (status === 503) {
87
+ const msg = body.detail ||
88
+ body.error ||
89
+ "AI Copilot is not configured on the server";
90
+ console.log(opts.plain
91
+ ? `✖ Auto-fix unavailable: ${msg}`
92
+ : pc.red(`✖ Auto-fix unavailable: ${msg}`));
93
+ return false;
94
+ }
64
95
  if (status >= 400) {
65
- throw new Error(body.detail || body.error || `Auto-fix failed (${status})`);
96
+ const msg = body.detail || body.error || `Auto-fix failed (${status})`;
97
+ console.log(opts.plain
98
+ ? `✖ Auto-fix unavailable: ${msg}`
99
+ : pc.red(`✖ Auto-fix unavailable: ${msg}`));
100
+ return false;
66
101
  }
67
102
  if (body.explanation) {
68
103
  console.log(opts.plain ? body.explanation : pc.bold(body.explanation));
@@ -155,6 +155,12 @@ export async function runWatch(cwd, cfg, opts) {
155
155
  interactive: true,
156
156
  });
157
157
  }
158
+ catch (err) {
159
+ const message = err instanceof Error ? err.message : "Auto-fix failed";
160
+ console.log(opts.plain
161
+ ? `✖ Auto-fix unavailable: ${message}`
162
+ : pc.red(`✖ Auto-fix unavailable: ${message}`));
163
+ }
158
164
  finally {
159
165
  if (process.stdin.isTTY && !opts.plain) {
160
166
  readline.emitKeypressEvents(process.stdin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rulecloud",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Real-time RuleCloud guardrails for AI coding agents",
5
5
  "keywords": [
6
6
  "rulecloud",