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EAAE,CAAC","sourcesContent":["import type { Context } from \"../context.ts\";\nimport {\n\ttype ExecutionEnv,\n\ttype ExecutionError,\n\terr,\n\tok,\n\ttype Result,\n\ttype ShellExecOptions,\n\ttype ShellOutputView,\n} from \"../types.ts\";\nimport { applyShellOutputUpdate, sanitizeShellOutput } from \"./output-capture.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface ShellCaptureProgress {\n\toutput: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tlastLineBytes: number;\n}\n\nexport interface ShellCaptureOptions extends Omit<ShellExecOptions, \"capture\" | \"onUpdate\"> {\n\tonChunk?: (chunk: string, getProgress: () => ShellCaptureProgress, context: Context) => void;\n\t/** Return shell execution failures with captured output instead of as a failed Result. */\n\treturnExecutionErrors?: boolean;\n}\n\nexport interface ShellCaptureResult extends ShellCaptureProgress {\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\texecutionError?: ExecutionError;\n}\n\nfunction progressFrom(output: ShellOutputView): ShellCaptureProgress {\n\treturn {\n\t\toutput: output.text,\n\t\ttruncation: { content: output.text, ...output.truncation },\n\t\t...(output.spillPath === undefined ? {} : { fullOutputPath: output.spillPath }),\n\t\tlastLineBytes: output.lastLineBytes ?? 0,\n\t};\n}\n\n/**\n * Compatibility collector for callers that need one bounded final view.\n * Source-side capture, adaptive publication, and spilling remain owned by the\n * execution environment.\n */\nexport async function executeShellWithCapture(\n\tenv: ExecutionEnv,\n\tcommand: string,\n\toptions: ShellCaptureOptions | undefined,\n\tcontext: Context,\n): Promise<Result<ShellCaptureResult, ExecutionError>> {\n\tlet output: ShellOutputView | undefined;\n\tconst result = await env.exec(\n\t\tcommand,\n\t\t{\n\t\t\tcwd: options?.cwd,\n\t\t\tenv: options?.env,\n\t\t\tinheritEnv: options?.inheritEnv,\n\t\t\ttimeout: options?.timeout,\n\t\t\tcapture: {\n\t\t\t\tlimits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: \"tail\" },\n\t\t\t\tspill: true,\n\t\t\t},\n\t\t\tonUpdate: (update, updateContext) => {\n\t\t\t\tconst previous = output;\n\t\t\t\toutput = applyShellOutputUpdate(output, update);\n\t\t\t\tconst chunk =\n\t\t\t\t\tupdate.kind === \"append\" || update.kind === \"slide\"\n\t\t\t\t\t\t? update.text\n\t\t\t\t\t\t: update.kind === \"replace\" && previous === undefined\n\t\t\t\t\t\t\t? output.text\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t// A metadata-only update and a post-cap replacement contain no new\n\t\t\t\t// incremental chunk. Reporting their complete view would duplicate bytes\n\t\t\t\t// for callers that accumulate this compatibility callback.\n\t\t\t\tif (chunk) options?.onChunk?.(chunk, () => progressFrom(output!), updateContext);\n\t\t\t},\n\t\t},\n\t\tcontext,\n\t);\n\n\tif (output === undefined) {\n\t\tconst { content, ...truncation } = truncateTail(\"\");\n\t\toutput = { text: content, truncation };\n\t}\n\tconst progress = progressFrom(output);\n\tif (!result.ok) {\n\t\tif (result.error.code === \"aborted\" || context.abortSignal?.aborted) {\n\t\t\treturn ok({ ...progress, exitCode: undefined, cancelled: true, truncated: progress.truncation.truncated });\n\t\t}\n\t\tif (options?.returnExecutionErrors) {\n\t\t\treturn ok({\n\t\t\t\t...progress,\n\t\t\t\texitCode: undefined,\n\t\t\t\tcancelled: false,\n\t\t\t\ttruncated: progress.truncation.truncated,\n\t\t\t\texecutionError: result.error,\n\t\t\t});\n\t\t}\n\t\treturn err(result.error);\n\t}\n\treturn ok({\n\t\t...progress,\n\t\texitCode: result.value.exitCode,\n\t\tcancelled: false,\n\t\ttruncated: result.value.truncation.truncated,\n\t});\n}\n\nexport { sanitizeShellOutput as sanitizeBinaryOutput };\n"]}