fix(shared): emit PowerShell zip entries as json lines

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-04 01:16:30 +09:00
parent 0c5deac232
commit 553a961338
@@ -4,6 +4,45 @@ import type { ArchiveEntry } from "../archive-entry-validator"
export type PowerShellZipExtractor = "pwsh" | "powershell" export type PowerShellZipExtractor = "pwsh" | "powershell"
type PowerShellZipEntryRecord = {
type: "file" | "directory" | "symlink"
name: string
target: string
}
function isPowerShellZipEntryRecord(value: unknown): value is PowerShellZipEntryRecord {
if (!value || typeof value !== "object") {
return false
}
const candidate = value as Record<string, unknown>
return (
(candidate.type === "file" || candidate.type === "directory" || candidate.type === "symlink") &&
typeof candidate.name === "string" &&
typeof candidate.target === "string"
)
}
export function parsePowerShellZipEntryLine(line: string): ArchiveEntry | null {
const parsedValue: unknown = JSON.parse(line)
if (!isPowerShellZipEntryRecord(parsedValue)) {
return null
}
if (parsedValue.type === "symlink") {
return {
path: parsedValue.name,
type: parsedValue.type,
linkPath: parsedValue.target,
}
}
return {
path: parsedValue.name,
type: parsedValue.type,
}
}
export async function listZipEntriesWithPowerShell( export async function listZipEntriesWithPowerShell(
archivePath: string, archivePath: string,
escapePowerShellPath: (path: string) => string, escapePowerShellPath: (path: string) => string,
@@ -28,7 +67,7 @@ export async function listZipEntriesWithPowerShell(
" try { $target = $reader.ReadToEnd() } finally { $reader.Dispose() }", " try { $target = $reader.ReadToEnd() } finally { $reader.Dispose() }",
" } finally { $stream.Dispose() }", " } finally { $stream.Dispose() }",
" }", " }",
" Write-Output ($type + \"`t\" + $entry.FullName + \"`t\" + $target)", " Write-Output (ConvertTo-Json @{type=$type; name=$entry.FullName; target=$target} -Compress)",
" }", " }",
"} finally {", "} finally {",
" $archive.Dispose()", " $archive.Dispose()",
@@ -55,24 +94,6 @@ export async function listZipEntriesWithPowerShell(
.split(/\r?\n/) .split(/\r?\n/)
.map(line => line.trim()) .map(line => line.trim())
.filter(Boolean) .filter(Boolean)
.map((line): ArchiveEntry | null => { .map(line => parsePowerShellZipEntryLine(line))
const [type, entryPath, linkPath = ""] = line.split("\t")
if (type !== "file" && type !== "directory" && type !== "symlink") {
return null
}
if (type === "symlink") {
return {
path: entryPath,
type,
linkPath,
}
}
return {
path: entryPath,
type,
}
})
.filter((entry): entry is ArchiveEntry => entry !== null) .filter((entry): entry is ArchiveEntry => entry !== null)
} }