refactor(core): simplify tool and shell code (#43948)

This commit is contained in:
Kit Langton
2026-08-21 14:45:05 -04:00
committed by GitHub
parent e68144cb67
commit 9a4bd2ba16
4 changed files with 9 additions and 13 deletions
-2
View File
@@ -158,8 +158,6 @@ function info(file: string, options?: Options, bin?: string): Item {
export function args(file: string, command: string) {
const n = name(file)
if (n === "nu" || n === "fish") return ["-c", command]
if (n === "zsh" || n === "bash") return ["-c", command]
if (n === "cmd") return ["/c", command]
if (ps(file)) return ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", command]
return ["-c", command]
+4 -4
View File
@@ -109,9 +109,10 @@ export function convertHTMLToMarkdown(html: string) {
outputBytes -= encoder.encode(value).byteLength
return value
}
const quotePrefix = () => "> ".repeat(Math.min(8, quoteDepth))
const prefixQuote = () => {
if (!needsQuotePrefix || quoteDepth === 0 || activeCell) return
append(`${"> ".repeat(Math.min(8, quoteDepth))}`)
append(quotePrefix())
needsQuotePrefix = false
}
const flushSpace = () => {
@@ -228,8 +229,7 @@ export function convertHTMLToMarkdown(html: string) {
const fence = marker.repeat(length)
block()
const prefix = `${fence}${code.language ?? ""}\n`
const quote = quoteDepth > 0 ? `${"> ".repeat(Math.min(8, quoteDepth))}` : ""
const closing = `${code.text.endsWith("\n") ? "" : "\n"}${fence}`
const quote = quoteDepth > 0 ? quotePrefix() : ""
let payload = code.text
for (;;) {
const candidate = `${prefix}${payload}${payload.endsWith("\n") ? "" : "\n"}${fence}`
@@ -606,7 +606,7 @@ export function convertHTMLToMarkdown(html: string) {
block()
}
if (!table.fallback && rectangular) {
const prefix = `${quoteDepth > 0 ? `${"> ".repeat(Math.min(8, quoteDepth))}` : ""}${pendingIndent}`
const prefix = `${quoteDepth > 0 ? quotePrefix() : ""}${pendingIndent}`
pendingIndent = ""
append(`${prefix}| ${table.rows[0].join(" | ")} |\n${prefix}|${" --- |".repeat(width)}`)
for (const row of table.rows.slice(1)) append(`\n${prefix}| ${row.join(" | ")} |`)
+1 -1
View File
@@ -87,7 +87,7 @@ const findLineOccurrences = (content: string, search: string) => {
if (
!actual.every(
(item, lineIndex) =>
normalizeForMatch(item.text.trimEnd()) === normalizeForMatch(expected[lineIndex]!.trimEnd()),
normalizeForMatch(item.text.trimEnd()) === normalizeForMatch(expected[lineIndex].trimEnd()),
)
)
return []
+4 -6
View File
@@ -101,15 +101,13 @@ const standardFailure = (prefix: string, error: unknown) =>
const inputJsonSchema = (schema: Tool.ValueSchema<any>): JsonSchema.JsonSchema => {
if (schema === undefined || schema === null) return {}
if (isStandardSchema(schema))
return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" }) as JsonSchema.JsonSchema
return Schema.isSchema(schema) ? toJsonSchema(schema) : (schema as JsonSchema.JsonSchema)
if (isStandardSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" })
return Schema.isSchema(schema) ? toJsonSchema(schema) : schema
}
const outputJsonSchema = (schema: Tool.ValueSchema<any>): JsonSchema.JsonSchema => {
if (isStandardSchema(schema))
return schema["~standard"].jsonSchema.output({ target: "draft-2020-12" }) as JsonSchema.JsonSchema
return Schema.isSchema(schema) ? toJsonSchema(schema) : (schema as JsonSchema.JsonSchema)
if (isStandardSchema(schema)) return schema["~standard"].jsonSchema.output({ target: "draft-2020-12" })
return Schema.isSchema(schema) ? toJsonSchema(schema) : schema
}
const toJsonSchema = (schema: Schema.Top): JsonSchema.JsonSchema => {