Skip to content

Commit 12011e5

Browse files
authored
Merge pull request #116 from asperpharma/copilot/add-diagnostic-script-powershell
Add Antigravity diagnostic script and feature-flagged diagnostic runner
2 parents 44c3f36 + 7b81816 commit 12011e5

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

env.main-site.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ VITE_LOVABLE_URL=asperbeautyshop-com.lovable.app
3434
# Leave empty to disable webhook sync (workflows will skip gracefully).
3535
LOVABLE_WEBHOOK_URL=
3636

37+
# ========== Feature Flags ==========
38+
# Controls the Antigravity Panel diagnostics and connection UI.
39+
# Set to true to enable; defaults to false (disabled) when unset.
40+
VITE_FEATURE_ANTIGRAVITY=false
41+
3742
# ========== Sync script (local / CI; NOT for Lovable) ==========
3843
# Get token from: Shopify Admin → Settings → Apps → Develop apps
3944
# → Create app → Configure Admin API scopes:

src/lib/antigravityFeature.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Antigravity Panel Feature Flag and Diagnostic Runner
3+
*
4+
* All new connection/diagnostic UI or workflow changes are controlled by the
5+
* FEATURE_ANTIGRAVITY flag, enabling safe, incremental rollout and easy toggling.
6+
*
7+
* To enable: set VITE_FEATURE_ANTIGRAVITY=true in your environment or .env file.
8+
* (See env.main-site.example for environment flag conventions.)
9+
*/
10+
11+
export const FEATURE_ANTIGRAVITY: boolean =
12+
typeof import.meta !== "undefined" &&
13+
import.meta.env &&
14+
typeof import.meta.env.VITE_FEATURE_ANTIGRAVITY !== "undefined"
15+
? String(import.meta.env.VITE_FEATURE_ANTIGRAVITY).toLowerCase() === "true"
16+
: false;
17+
18+
/**
19+
* Run the Antigravity diagnostic script and return a status/result object.
20+
*
21+
* Only executes when FEATURE_ANTIGRAVITY is true and in a Node.js environment
22+
* (i.e. not in the browser). Runs scripts/antigravity-diagnostic.ps1 via
23+
* PowerShell and interprets the output.
24+
*
25+
* Returns a standardised result suitable for display in UI or workflow logs:
26+
* - "success" — language server process found
27+
* - "no_process" — script ran but no Antigravity process detected
28+
* - "error" — feature disabled, wrong environment, or script error
29+
* - "escalate" — script output indicates uncertainty; needs human review
30+
*/
31+
export async function runAntigravityDiagnostic(): Promise<{
32+
status: "success" | "no_process" | "error" | "escalate";
33+
details: string;
34+
}> {
35+
if (!FEATURE_ANTIGRAVITY) {
36+
return {
37+
status: "error",
38+
details: "Antigravity diagnostics are disabled by feature flag.",
39+
};
40+
}
41+
42+
// Only attempt in a Node.js-capable environment, not in the browser.
43+
if (typeof window !== "undefined") {
44+
return {
45+
status: "error",
46+
details: "Cannot run PowerShell diagnostics in browser environment.",
47+
};
48+
}
49+
50+
try {
51+
// Dynamic imports to avoid bundling Node built-ins into the browser bundle.
52+
const { exec } = await import("child_process");
53+
const nodePath = await import("path");
54+
const util = await import("util");
55+
const execAsync = util.promisify(exec);
56+
57+
// Use path.join so this works correctly on any platform (PowerShell also
58+
// accepts forward-slash separators on Windows).
59+
const scriptPath = nodePath.join("scripts", "antigravity-diagnostic.ps1");
60+
const { stdout } = await execAsync(
61+
`powershell -NoProfile -ExecutionPolicy Bypass -File "${scriptPath}"`
62+
);
63+
64+
if (
65+
stdout?.includes("no language_server_windows_x64.exe") ||
66+
stdout?.toLowerCase().includes("no_process")
67+
) {
68+
return {
69+
status: "no_process",
70+
details: stdout.trim(),
71+
};
72+
}
73+
74+
return {
75+
status: "success",
76+
details: stdout?.trim() || "Diagnostic succeeded.",
77+
};
78+
} catch (err: unknown) {
79+
const error = err as { stderr?: string; message?: string };
80+
const detail =
81+
error?.stderr || error?.message || "Unknown error in diagnosis script";
82+
return {
83+
status:
84+
detail.includes("uncertain") || detail.includes("cannot detect")
85+
? "escalate"
86+
: "error",
87+
details: detail,
88+
};
89+
}
90+
}

0 commit comments

Comments
 (0)