feat(walkthrough): plan-then-explain generation with selectable diff sources

This commit is contained in:
Chris Scott committed 2026-10-08 15:53:49 -04:00
1 parent aeea96b466
commit 88b3543dc1
35 files changed
+2583 -609

No files matched your search

+44
View File
@@ -21,3 +21,47 @@ export async function mapWithConcurrency<T, R>(
await Promise.all(Array.from({ length: workerCount }, () => worker()))
return results
}
export interface Limiter {
readonly activeCount: number
run<T>(task: () => Promise<T>): Promise<T>
}
export function createLimiter(limit: number): Limiter {
const max = Math.max(1, limit)
let active = 0
const waiters: Array<() => void> = []
const acquire = (): Promise<void> => {
if (active < max) {
active += 1
return Promise.resolve()
}
return new Promise<void>((resolve) => {
waiters.push(resolve)
})
}
const release = (): void => {
const next = waiters.shift()
if (next) {
next()
return
}
active -= 1
}
return {
get activeCount(): number {
return active
},
async run<T>(task: () => Promise<T>): Promise<T> {
await acquire()
try {
return await task()
} finally {
release()
}
},
}
}
+23
View File
@@ -1,3 +1,5 @@
import type { ZodType } from 'zod'
export function extractFirstJsonObject(text: string): string | null {
const start = text.indexOf('{')
if (start === -1) {
@@ -39,3 +41,24 @@ export function extractFirstJsonObject(text: string): string | null {
return null
}
export function parseFirstJsonObject<T>(text: string, schema: ZodType<T>): T | null {
const extracted = extractFirstJsonObject(text)
if (!extracted) {
return null
}
let raw: unknown
try {
raw = JSON.parse(extracted)
} catch {
return null
}
const parsed = schema.safeParse(raw)
if (!parsed.success) {
return null
}
return parsed.data
}
+15 -13
View File
@@ -10,23 +10,24 @@ interface ExecuteCommandOptions {
maxOutputChars?: number
}
export async function executeCommand(
export interface ExecuteCommandResult {
exitCode: number
stdout: string
stderr: string
truncated?: boolean
}
type ExecuteCommandReturn<O> = O extends { ignoreExitCode: true } ? ExecuteCommandResult : string
export async function executeCommand<O extends ExecuteCommandOptions = ExecuteCommandOptions>(
args: string[],
cwdOrOptions?: string | ExecuteCommandOptions
): Promise<string>
export async function executeCommand(
args: string[],
cwdOrOptions: string | (ExecuteCommandOptions & { ignoreExitCode: true })
): Promise<string | { exitCode: number; stdout: string; stderr: string }>
export async function executeCommand(
args: string[],
cwdOrOptions?: string | ExecuteCommandOptions
): Promise<string | { exitCode: number; stdout: string; stderr: string }> {
cwdOrOptions?: string | O
): Promise<ExecuteCommandReturn<O>> {
const options: ExecuteCommandOptions = typeof cwdOrOptions === 'string'
? { cwd: cwdOrOptions }
: cwdOrOptions || {}
return new Promise((resolve, reject) => {
return new Promise<string | ExecuteCommandResult>((resolve, reject) => {
const [command, ...cmdArgs] = args
const effectiveEnv = { ...process.env, ...options.env }
@@ -103,6 +104,7 @@ export async function executeCommand(
exitCode,
stdout,
stderr: terminatedBySignal ? `${stderr}Command terminated by signal ${signal}` : stderr,
truncated: true,
}
: stdout)
} else if (options.ignoreExitCode) {
@@ -121,5 +123,5 @@ export async function executeCommand(
reject(error)
}
})
})
}) as Promise<ExecuteCommandReturn<O>>
}