Merge pull request #1602 from code-yeongyu/fix/1365-sg-cli-path-fallback
fix: don't fallback to system sg command for ast-grep (#1365)
This commit is contained in:
commit
e1010846c4
@ -421,7 +421,7 @@ export function buildUltraworkSection(
|
|||||||
|
|
||||||
lines.push("**Agents** (for specialized consultation/exploration):")
|
lines.push("**Agents** (for specialized consultation/exploration):")
|
||||||
for (const agent of sortedAgents) {
|
for (const agent of sortedAgents) {
|
||||||
const shortDesc = agent.description.split(".")[0] || agent.description
|
const shortDesc = agent.description.length > 120 ? agent.description.slice(0, 120) + "..." : agent.description
|
||||||
const suffix = agent.name === "explore" || agent.name === "librarian" ? " (multiple)" : ""
|
const suffix = agent.name === "explore" || agent.name === "librarian" ? " (multiple)" : ""
|
||||||
lines.push(`- \`${agent.name}${suffix}\`: ${shortDesc}`)
|
lines.push(`- \`${agent.name}${suffix}\`: ${shortDesc}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,10 +86,22 @@ export async function runSg(options: RunOptions): Promise<SgResult> {
|
|||||||
|
|
||||||
let cliPath = getSgCliPath()
|
let cliPath = getSgCliPath()
|
||||||
|
|
||||||
if (!existsSync(cliPath) && cliPath !== "sg") {
|
if (!cliPath || !existsSync(cliPath)) {
|
||||||
const downloadedPath = await getAstGrepPath()
|
const downloadedPath = await getAstGrepPath()
|
||||||
if (downloadedPath) {
|
if (downloadedPath) {
|
||||||
cliPath = downloadedPath
|
cliPath = downloadedPath
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
matches: [],
|
||||||
|
totalMatches: 0,
|
||||||
|
truncated: false,
|
||||||
|
error:
|
||||||
|
`ast-grep (sg) binary not found.\n\n` +
|
||||||
|
`Install options:\n` +
|
||||||
|
` bun add -D @ast-grep/cli\n` +
|
||||||
|
` cargo install ast-grep --locked\n` +
|
||||||
|
` brew install ast-grep`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ export function findSgCliPathSync(): string | null {
|
|||||||
|
|
||||||
let resolvedCliPath: string | null = null
|
let resolvedCliPath: string | null = null
|
||||||
|
|
||||||
export function getSgCliPath(): string {
|
export function getSgCliPath(): string | null {
|
||||||
if (resolvedCliPath !== null) {
|
if (resolvedCliPath !== null) {
|
||||||
return resolvedCliPath
|
return resolvedCliPath
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ export function getSgCliPath(): string {
|
|||||||
return syncPath
|
return syncPath
|
||||||
}
|
}
|
||||||
|
|
||||||
return "sg"
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setSgCliPath(path: string): void {
|
export function setSgCliPath(path: string): void {
|
||||||
@ -186,29 +186,17 @@ export function checkEnvironment(): EnvironmentCheckResult {
|
|||||||
const result: EnvironmentCheckResult = {
|
const result: EnvironmentCheckResult = {
|
||||||
cli: {
|
cli: {
|
||||||
available: false,
|
available: false,
|
||||||
path: cliPath,
|
path: cliPath ?? "not found",
|
||||||
},
|
},
|
||||||
napi: {
|
napi: {
|
||||||
available: false,
|
available: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existsSync(cliPath)) {
|
if (cliPath && existsSync(cliPath)) {
|
||||||
result.cli.available = true
|
result.cli.available = true
|
||||||
} else if (cliPath === "sg") {
|
} else if (!cliPath) {
|
||||||
try {
|
result.cli.error = "ast-grep binary not found. Install with: bun add -D @ast-grep/cli"
|
||||||
const { spawnSync } = require("child_process")
|
|
||||||
const whichResult = spawnSync(process.platform === "win32" ? "where" : "which", ["sg"], {
|
|
||||||
encoding: "utf-8",
|
|
||||||
timeout: 5000,
|
|
||||||
})
|
|
||||||
result.cli.available = whichResult.status === 0 && !!whichResult.stdout?.trim()
|
|
||||||
if (!result.cli.available) {
|
|
||||||
result.cli.error = "sg binary not found in PATH"
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
result.cli.error = "Failed to check sg availability"
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
result.cli.error = `Binary not found: ${cliPath}`
|
result.cli.error = `Binary not found: ${cliPath}`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user