fix: address Cubic P2 issues in CLI modules
This commit is contained in:
parent
ce37924fd8
commit
babcb0050a
@ -1,4 +1,4 @@
|
|||||||
import { writeFileSync } from "node:fs"
|
import { readFileSync, writeFileSync } from "node:fs"
|
||||||
import type { ConfigMergeResult, InstallConfig } from "../types"
|
import type { ConfigMergeResult, InstallConfig } from "../types"
|
||||||
import { getConfigDir } from "./config-context"
|
import { getConfigDir } from "./config-context"
|
||||||
import { ensureConfigDirectoryExists } from "./ensure-config-directory-exists"
|
import { ensureConfigDirectoryExists } from "./ensure-config-directory-exists"
|
||||||
@ -55,7 +55,27 @@ export async function addAuthPlugins(config: InstallConfig): Promise<ConfigMerge
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newConfig = { ...(existingConfig ?? {}), plugin: plugins }
|
const newConfig = { ...(existingConfig ?? {}), plugin: plugins }
|
||||||
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n")
|
|
||||||
|
if (format === "jsonc") {
|
||||||
|
const content = readFileSync(path, "utf-8")
|
||||||
|
const pluginArrayRegex = /"plugin"\s*:\s*\[([\s\S]*?)\]/
|
||||||
|
const match = content.match(pluginArrayRegex)
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const formattedPlugins = plugins.map((p) => `"${p}"`).join(",\n ")
|
||||||
|
const newContent = content.replace(
|
||||||
|
pluginArrayRegex,
|
||||||
|
`"plugin": [\n ${formattedPlugins}\n ]`
|
||||||
|
)
|
||||||
|
writeFileSync(path, newContent)
|
||||||
|
} else {
|
||||||
|
const inlinePlugins = plugins.map((p) => `"${p}"`).join(", ")
|
||||||
|
const newContent = content.replace(/(\{)/, `$1\n "plugin": [${inlinePlugins}],`)
|
||||||
|
writeFileSync(path, newContent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
writeFileSync(path, JSON.stringify(newConfig, null, 2) + "\n")
|
||||||
|
}
|
||||||
return { success: true, configPath: path }
|
return { success: true, configPath: path }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -18,8 +18,8 @@ export async function runBunInstallWithDetails(): Promise<BunInstallResult> {
|
|||||||
try {
|
try {
|
||||||
const proc = Bun.spawn(["bun", "install"], {
|
const proc = Bun.spawn(["bun", "install"], {
|
||||||
cwd: getConfigDir(),
|
cwd: getConfigDir(),
|
||||||
stdout: "pipe",
|
stdout: "inherit",
|
||||||
stderr: "pipe",
|
stderr: "inherit",
|
||||||
})
|
})
|
||||||
|
|
||||||
let timeoutId: ReturnType<typeof setTimeout>
|
let timeoutId: ReturnType<typeof setTimeout>
|
||||||
@ -44,10 +44,9 @@ export async function runBunInstallWithDetails(): Promise<BunInstallResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (proc.exitCode !== 0) {
|
if (proc.exitCode !== 0) {
|
||||||
const stderr = await new Response(proc.stderr).text()
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: stderr.trim() || `bun install failed with exit code ${proc.exitCode}`,
|
error: `bun install failed with exit code ${proc.exitCode}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,9 +103,19 @@ export function logEventVerbose(ctx: RunContext, payload: EventPayload): void {
|
|||||||
const toolProps = props as ToolExecuteProps | undefined
|
const toolProps = props as ToolExecuteProps | undefined
|
||||||
const toolName = toolProps?.name ?? "unknown"
|
const toolName = toolProps?.name ?? "unknown"
|
||||||
const input = toolProps?.input ?? {}
|
const input = toolProps?.input ?? {}
|
||||||
const inputStr = JSON.stringify(input).slice(0, 150)
|
let inputStr: string
|
||||||
|
try {
|
||||||
|
inputStr = JSON.stringify(input)
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
inputStr = String(input)
|
||||||
|
} catch {
|
||||||
|
inputStr = "[unserializable]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const inputPreview = inputStr.slice(0, 150)
|
||||||
console.error(pc.cyan(`${sessionTag} TOOL.EXECUTE: ${pc.bold(toolName)}`))
|
console.error(pc.cyan(`${sessionTag} TOOL.EXECUTE: ${pc.bold(toolName)}`))
|
||||||
console.error(pc.dim(` input: ${inputStr}${inputStr.length >= 150 ? "..." : ""}`))
|
console.error(pc.dim(` input: ${inputPreview}${inputStr.length >= 150 ? "..." : ""}`))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ async function selectOrCancel<TValue extends Readonly<string | boolean | number>
|
|||||||
options: Option<TValue>[]
|
options: Option<TValue>[]
|
||||||
initialValue: TValue
|
initialValue: TValue
|
||||||
}): Promise<TValue | null> {
|
}): Promise<TValue | null> {
|
||||||
|
if (!process.stdin.isTTY) return null
|
||||||
|
|
||||||
const value = await p.select<TValue>({
|
const value = await p.select<TValue>({
|
||||||
message: params.message,
|
message: params.message,
|
||||||
options: params.options,
|
options: params.options,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user