@caupulican/pi-adaptative 0.91.4 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cli.js +6 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  5. package/dist/core/autonomy/lane-tool-surface.js +7 -1
  6. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  7. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  8. package/dist/core/bash-execution-controller.js +1 -0
  9. package/dist/core/bash-execution-controller.js.map +1 -1
  10. package/dist/core/bash-executor.d.ts +2 -0
  11. package/dist/core/bash-executor.d.ts.map +1 -1
  12. package/dist/core/bash-executor.js +13 -4
  13. package/dist/core/bash-executor.js.map +1 -1
  14. package/dist/core/tools/bash.d.ts +2 -0
  15. package/dist/core/tools/bash.d.ts.map +1 -1
  16. package/dist/core/tools/bash.js +27 -12
  17. package/dist/core/tools/bash.js.map +1 -1
  18. package/dist/core/tools/early-powershell-session.d.ts +21 -0
  19. package/dist/core/tools/early-powershell-session.d.ts.map +1 -0
  20. package/dist/core/tools/early-powershell-session.js +137 -0
  21. package/dist/core/tools/early-powershell-session.js.map +1 -0
  22. package/dist/core/tools/output-accumulator.d.ts +2 -0
  23. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  24. package/dist/core/tools/output-accumulator.js +2 -1
  25. package/dist/core/tools/output-accumulator.js.map +1 -1
  26. package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -1
  27. package/dist/core/tools/persistent-process-coordinator.js +2 -11
  28. package/dist/core/tools/persistent-process-coordinator.js.map +1 -1
  29. package/dist/core/tools/shell-output-decoder.d.ts +7 -0
  30. package/dist/core/tools/shell-output-decoder.d.ts.map +1 -0
  31. package/dist/core/tools/shell-output-decoder.js +135 -0
  32. package/dist/core/tools/shell-output-decoder.js.map +1 -0
  33. package/dist/core/tools/shell-session.d.ts +23 -6
  34. package/dist/core/tools/shell-session.d.ts.map +1 -1
  35. package/dist/core/tools/shell-session.js +275 -88
  36. package/dist/core/tools/shell-session.js.map +1 -1
  37. package/dist/utils/child-process-ref.d.ts +4 -0
  38. package/dist/utils/child-process-ref.d.ts.map +1 -0
  39. package/dist/utils/child-process-ref.js +15 -0
  40. package/dist/utils/child-process-ref.js.map +1 -0
  41. package/dist/utils/powershell-session-protocol.d.ts +16 -0
  42. package/dist/utils/powershell-session-protocol.d.ts.map +1 -0
  43. package/dist/utils/powershell-session-protocol.js +63 -0
  44. package/dist/utils/powershell-session-protocol.js.map +1 -0
  45. package/dist/utils/shell.d.ts +7 -4
  46. package/dist/utils/shell.d.ts.map +1 -1
  47. package/dist/utils/shell.js +38 -23
  48. package/dist/utils/shell.js.map +1 -1
  49. package/docs/settings.md +2 -2
  50. package/docs/windows.md +9 -8
  51. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  52. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  53. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  54. package/examples/extensions/sandbox/package-lock.json +2 -2
  55. package/examples/extensions/sandbox/package.json +1 -1
  56. package/examples/extensions/with-deps/package-lock.json +2 -2
  57. package/examples/extensions/with-deps/package.json +1 -1
  58. package/npm-shrinkwrap.json +12 -12
  59. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EAEjB,qBAAqB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,W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,aAAa,IAAI,mBAAmB,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EAEjB,qBAAqB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,wBAAwB,E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aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport { createShellOutputDecoder, type ShellOutputDecoder } from \"./shell-output-decoder.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n\t/** Decode valid UTF-8 plus isolated Windows-1252 bytes from native Windows programs. */\n\twindowsCompatibleEncoding?: boolean;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder: ShellOutputDecoder;\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t\tthis.decoder = createShellOutputDecoder(options.windowsCompatibleEncoding);\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACnC;AAaD,qBAAa,4BAA4B;IACxC,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,cAGC;IAED,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,CAE/B;IAED,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnD;IAED,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;IAED,IAAI,IAAI,IAAI,CAKX;IAED,OAAO,IAAI,IAAI,CAKd;IAED,mEAAmE;IACnE,kBAAkB,IAAI,IAAI,CAEzB;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAchC;IAED,OAAO,CAAC,KAAK;CAMb"}
1
+ {"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACnC;AAaD,qBAAa,4BAA4B;IACxC,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,cAGC;IAED,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,CAE/B;IAED,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnD;IAED,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;IAED,IAAI,IAAI,IAAI,CAKX;IAED,OAAO,IAAI,IAAI,CAKd;IAED,mEAAmE;IACnE,kBAAkB,IAAI,IAAI,CAEzB;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAIhC;IAED,OAAO,CAAC,KAAK;CAMb"}
@@ -5,6 +5,7 @@
5
5
  * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale
6
6
  * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.
7
7
  */
8
+ import { setChildProcessLoopRef } from "../../utils/child-process-ref.js";
8
9
  import { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from "../../utils/shell.js";
9
10
  const liveCoordinators = new Set();
10
11
  let exitHookInstalled = false;
@@ -99,17 +100,7 @@ export class PersistentProcessCoordinator {
99
100
  const child = this.currentChild;
100
101
  if (!child)
101
102
  return;
102
- const streams = [child.stdin, child.stdout, child.stderr];
103
- if (active) {
104
- child.ref();
105
- for (const stream of streams)
106
- stream?.ref?.();
107
- }
108
- else {
109
- child.unref();
110
- for (const stream of streams)
111
- stream?.unref?.();
112
- }
103
+ setChildProcessLoopRef(child, active);
113
104
  }
114
105
  clear(child) {
115
106
  if (this.currentChild !== child)
@@ -1 +1 @@
1
- {"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,E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,CAAC,KAAmB;QAChC,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/**\n * Shared lifecycle owner for one serialized, persistent child process.\n *\n * Wire protocols, state projection, and respawn policy stay with their concrete shell adapters.\n * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale\n * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.\n */\n\nimport type { ChildProcess } from \"node:child_process\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface PersistentChildHandlers {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonError(error: Error): void;\n\tonClose(code: number | null): void;\n}\n\nconst liveCoordinators = new Set<PersistentProcessCoordinator>();\nlet exitHookInstalled = false;\n\nfunction installExitHook(): void {\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.on(\"exit\", () => {\n\t\tfor (const coordinator of liveCoordinators) coordinator.killForProcessExit();\n\t});\n}\n\nexport class PersistentProcessCoordinator {\n\tprivate currentChild: ChildProcess | null = null;\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate disposed = false;\n\n\tconstructor() {\n\t\tinstallExitHook();\n\t\tliveCoordinators.add(this);\n\t}\n\n\tget child(): ChildProcess | null {\n\t\treturn this.currentChild;\n\t}\n\n\trunSerialized<T>(task: () => Promise<T>): Promise<T> {\n\t\tconst run = this.queue.then(task);\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tattach(child: ChildProcess, handlers: PersistentChildHandlers): void {\n\t\tif (this.disposed) {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\tthrow new Error(\"Persistent process coordinator is disposed\");\n\t\t}\n\t\tif (this.currentChild) throw new Error(\"Persistent process coordinator already owns a child\");\n\t\tthis.currentChild = child;\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\tchild.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStdout(data);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStderr(data);\n\t\t});\n\t\tchild.on(\"error\", (error) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onError(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\t// Process death is authoritative. Defer one check phase so stream data already delivered\n\t\t// by the kernel reaches the active protocol handler before the terminal callback.\n\t\tchild.on(\"exit\", (code) => {\n\t\t\tif (this.currentChild !== child) return;\n\t\t\tsetImmediate(() => {\n\t\t\t\tif (!this.clear(child)) return;\n\t\t\t\thandlers.onClose(code);\n\t\t\t});\n\t\t});\n\t\t// A genuine close may arrive first; `clear` makes exit/close settlement idempotent.\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onClose(code);\n\t\t});\n\t}\n\n\tkill(): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tthis.clear(child);\n\t\tif (child.pid) killProcessTree(child.pid);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tliveCoordinators.delete(this);\n\t\tthis.kill();\n\t}\n\n\t/** Synchronous best-effort tree kill for the process exit hook. */\n\tkillForProcessExit(): void {\n\t\tthis.kill();\n\t}\n\n\t/** Idle coordinators must not keep one-shot Node modes alive; active commands must. */\n\tsetLoopRef(active: boolean): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tconst streams = [child.stdin, child.stdout, child.stderr] as unknown as Array<{\n\t\t\tref?: () => void;\n\t\t\tunref?: () => void;\n\t\t} | null>;\n\t\tif (active) {\n\t\t\tchild.ref();\n\t\t\tfor (const stream of streams) stream?.ref?.();\n\t\t} else {\n\t\t\tchild.unref();\n\t\t\tfor (const stream of streams) stream?.unref?.();\n\t\t}\n\t}\n\n\tprivate clear(child: ChildProcess): boolean {\n\t\tif (this.currentChild !== child) return false;\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tthis.currentChild = null;\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AASvG,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;AACjE,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,SAAS,eAAe;IACvB,IAAI,iBAAiB;QAAE,OAAO;IAC9B,iBAAiB,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACvB,KAAK,MAAM,WAAW,IAAI,gBAAgB;YAAE,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC9E,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,4BAA4B;IAKxC;QAJQ,iBAAY,GAAwB,IAAI,CAAC;QACzC,UAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QACzC,aAAQ,GAAG,KAAK,CAAC;QAGxB,eAAe,EAAE,CAAC;QAClB,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED,aAAa,CAAI,IAAsB;QACtC,MAAM,GAAG,GAAG,IAAI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ACzB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEO,KAAK,CAAC,KAAmB;QAChC,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/**\n * Shared lifecycle owner for one serialized, persistent child process.\n *\n * Wire protocols, state projection, and respawn policy stay with their concrete shell adapters.\n * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale\n * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.\n */\n\nimport type { ChildProcess } from \"node:child_process\";\nimport { setChildProcessLoopRef } from \"../../utils/child-process-ref.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface PersistentChildHandlers {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonError(error: Error): void;\n\tonClose(code: number | null): void;\n}\n\nconst liveCoordinators = new Set<PersistentProcessCoordinator>();\nlet exitHookInstalled = false;\n\nfunction installExitHook(): void {\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.on(\"exit\", () => {\n\t\tfor (const coordinator of liveCoordinators) coordinator.killForProcessExit();\n\t});\n}\n\nexport class PersistentProcessCoordinator {\n\tprivate currentChild: ChildProcess | null = null;\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate disposed = false;\n\n\tconstructor() {\n\t\tinstallExitHook();\n\t\tliveCoordinators.add(this);\n\t}\n\n\tget child(): ChildProcess | null {\n\t\treturn this.currentChild;\n\t}\n\n\trunSerialized<T>(task: () => Promise<T>): Promise<T> {\n\t\tconst run = this.queue.then(task);\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tattach(child: ChildProcess, handlers: PersistentChildHandlers): void {\n\t\tif (this.disposed) {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\tthrow new Error(\"Persistent process coordinator is disposed\");\n\t\t}\n\t\tif (this.currentChild) throw new Error(\"Persistent process coordinator already owns a child\");\n\t\tthis.currentChild = child;\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\tchild.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStdout(data);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStderr(data);\n\t\t});\n\t\tchild.on(\"error\", (error) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onError(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\t// Process death is authoritative. Defer one check phase so stream data already delivered\n\t\t// by the kernel reaches the active protocol handler before the terminal callback.\n\t\tchild.on(\"exit\", (code) => {\n\t\t\tif (this.currentChild !== child) return;\n\t\t\tsetImmediate(() => {\n\t\t\t\tif (!this.clear(child)) return;\n\t\t\t\thandlers.onClose(code);\n\t\t\t});\n\t\t});\n\t\t// A genuine close may arrive first; `clear` makes exit/close settlement idempotent.\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onClose(code);\n\t\t});\n\t}\n\n\tkill(): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tthis.clear(child);\n\t\tif (child.pid) killProcessTree(child.pid);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tliveCoordinators.delete(this);\n\t\tthis.kill();\n\t}\n\n\t/** Synchronous best-effort tree kill for the process exit hook. */\n\tkillForProcessExit(): void {\n\t\tthis.kill();\n\t}\n\n\t/** Idle coordinators must not keep one-shot Node modes alive; active commands must. */\n\tsetLoopRef(active: boolean): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tsetChildProcessLoopRef(child, active);\n\t}\n\n\tprivate clear(child: ChildProcess): boolean {\n\t\tif (this.currentChild !== child) return false;\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tthis.currentChild = null;\n\t\treturn true;\n\t}\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export interface ShellOutputDecoder {
2
+ decode(input?: Uint8Array, options?: {
3
+ stream?: boolean;
4
+ }): string;
5
+ }
6
+ export declare function createShellOutputDecoder(windowsCompatible?: boolean): ShellOutputDecoder;
7
+ //# sourceMappingURL=shell-output-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-output-decoder.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-output-decoder.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IAClC,MAAM,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC;CACnE;AAiID,wBAAgB,wBAAwB,CAAC,iBAAiB,UAAQ,GAAG,kBAAkB,CAEtF"}
@@ -0,0 +1,135 @@
1
+ const WINDOWS_1252_EXTENSION = [
2
+ "\u20ac",
3
+ "\u0081",
4
+ "\u201a",
5
+ "\u0192",
6
+ "\u201e",
7
+ "\u2026",
8
+ "\u2020",
9
+ "\u2021",
10
+ "\u02c6",
11
+ "\u2030",
12
+ "\u0160",
13
+ "\u2039",
14
+ "\u0152",
15
+ "\u008d",
16
+ "\u017d",
17
+ "\u008f",
18
+ "\u0090",
19
+ "\u2018",
20
+ "\u2019",
21
+ "\u201c",
22
+ "\u201d",
23
+ "\u2022",
24
+ "\u2013",
25
+ "\u2014",
26
+ "\u02dc",
27
+ "\u2122",
28
+ "\u0161",
29
+ "\u203a",
30
+ "\u0153",
31
+ "\u009d",
32
+ "\u017e",
33
+ "\u0178",
34
+ ];
35
+ const FATAL_UTF8_DECODER = new TextDecoder("utf8", { fatal: true });
36
+ function utf8SequenceLength(byte) {
37
+ if (byte >= 0xc2 && byte <= 0xdf)
38
+ return 2;
39
+ if (byte >= 0xe0 && byte <= 0xef)
40
+ return 3;
41
+ if (byte >= 0xf0 && byte <= 0xf4)
42
+ return 4;
43
+ return 0;
44
+ }
45
+ function isContinuation(byte) {
46
+ return byte >= 0x80 && byte <= 0xbf;
47
+ }
48
+ function isValidUtf8Sequence(bytes, index, length) {
49
+ const first = bytes[index] ?? 0;
50
+ const second = bytes[index + 1] ?? 0;
51
+ if (!isContinuation(second))
52
+ return false;
53
+ if (length === 2)
54
+ return true;
55
+ const third = bytes[index + 2] ?? 0;
56
+ if (!isContinuation(third))
57
+ return false;
58
+ if (first === 0xe0 && second < 0xa0)
59
+ return false;
60
+ if (first === 0xed && second > 0x9f)
61
+ return false;
62
+ if (length === 3)
63
+ return true;
64
+ const fourth = bytes[index + 3] ?? 0;
65
+ if (!isContinuation(fourth))
66
+ return false;
67
+ if (first === 0xf0 && second < 0x90)
68
+ return false;
69
+ if (first === 0xf4 && second > 0x8f)
70
+ return false;
71
+ return true;
72
+ }
73
+ function decodeWindows1252Byte(byte) {
74
+ if (byte >= 0x80 && byte <= 0x9f)
75
+ return WINDOWS_1252_EXTENSION[byte - 0x80] ?? "\ufffd";
76
+ return String.fromCodePoint(byte);
77
+ }
78
+ /**
79
+ * Decode valid UTF-8 sequences while recovering isolated legacy Windows-1252 bytes. ASCII is
80
+ * shared by both encodings, and at most three trailing bytes are retained across stream chunks.
81
+ */
82
+ class WindowsCompatibleShellOutputDecoder {
83
+ constructor() {
84
+ this.pending = Buffer.alloc(0);
85
+ }
86
+ decode(input = Buffer.alloc(0), options = {}) {
87
+ const incoming = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
88
+ const bytes = this.pending.length > 0 ? Buffer.concat([this.pending, incoming]) : incoming;
89
+ this.pending = Buffer.alloc(0);
90
+ if (bytes.length === 0)
91
+ return "";
92
+ try {
93
+ return FATAL_UTF8_DECODER.decode(bytes);
94
+ }
95
+ catch {
96
+ // Legacy bytes or a split trailing UTF-8 sequence need the compatibility scan below.
97
+ }
98
+ const decoded = [];
99
+ let utf8Start = 0;
100
+ let index = 0;
101
+ const appendUtf8 = (end) => {
102
+ if (end > utf8Start)
103
+ decoded.push(bytes.subarray(utf8Start, end).toString("utf8"));
104
+ };
105
+ while (index < bytes.length) {
106
+ const byte = bytes[index] ?? 0;
107
+ if (byte <= 0x7f) {
108
+ index += 1;
109
+ continue;
110
+ }
111
+ const sequenceLength = utf8SequenceLength(byte);
112
+ if (sequenceLength > 0 && index + sequenceLength > bytes.length && options.stream === true) {
113
+ appendUtf8(index);
114
+ this.pending = Buffer.from(bytes.subarray(index));
115
+ return decoded.join("");
116
+ }
117
+ if (sequenceLength > 0 &&
118
+ index + sequenceLength <= bytes.length &&
119
+ isValidUtf8Sequence(bytes, index, sequenceLength)) {
120
+ index += sequenceLength;
121
+ continue;
122
+ }
123
+ appendUtf8(index);
124
+ decoded.push(decodeWindows1252Byte(byte));
125
+ index += 1;
126
+ utf8Start = index;
127
+ }
128
+ appendUtf8(bytes.length);
129
+ return decoded.join("");
130
+ }
131
+ }
132
+ export function createShellOutputDecoder(windowsCompatible = false) {
133
+ return windowsCompatible ? new WindowsCompatibleShellOutputDecoder() : new TextDecoder();
134
+ }
135
+ //# sourceMappingURL=shell-output-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-output-decoder.js","sourceRoot":"","sources":["../../../src/core/tools/shell-output-decoder.ts"],"names":[],"mappings":"AAIA,MAAM,sBAAsB,GAAG;IAC9B,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;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AC,EAAE,CAAC,CAAC;YACzB,CAAC;YACD,IACC,cAAc,GAAG,CAAC;gBAClB,KAAK,GAAG,cAAc,IAAI,KAAK,CAAC,MAAM;gBACtC,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,EAChD,CAAC;gBACF,KAAK,IAAI,cAAc,CAAC;gBACxB,SAAS;YACV,CAAC;YAED,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1C,KAAK,IAAI,CAAC,CAAC;YACX,SAAS,GAAG,KAAK,CAAC;QACnB,CAAC;QAED,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACzB,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;CACD;AAED,MAAM,UAAU,wBAAwB,CAAC,iBAAiB,GAAG,KAAK;IACjE,OAAO,iBAAiB,CAAC,CAAC,CAAC,IAAI,mCAAmC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;AAC1F,CAAC","sourcesContent":["export interface ShellOutputDecoder {\n\tdecode(input?: Uint8Array, options?: { stream?: boolean }): string;\n}\n\nconst WINDOWS_1252_EXTENSION = [\n\t\"\\u20ac\",\n\t\"\\u0081\",\n\t\"\\u201a\",\n\t\"\\u0192\",\n\t\"\\u201e\",\n\t\"\\u2026\",\n\t\"\\u2020\",\n\t\"\\u2021\",\n\t\"\\u02c6\",\n\t\"\\u2030\",\n\t\"\\u0160\",\n\t\"\\u2039\",\n\t\"\\u0152\",\n\t\"\\u008d\",\n\t\"\\u017d\",\n\t\"\\u008f\",\n\t\"\\u0090\",\n\t\"\\u2018\",\n\t\"\\u2019\",\n\t\"\\u201c\",\n\t\"\\u201d\",\n\t\"\\u2022\",\n\t\"\\u2013\",\n\t\"\\u2014\",\n\t\"\\u02dc\",\n\t\"\\u2122\",\n\t\"\\u0161\",\n\t\"\\u203a\",\n\t\"\\u0153\",\n\t\"\\u009d\",\n\t\"\\u017e\",\n\t\"\\u0178\",\n] as const;\nconst FATAL_UTF8_DECODER = new TextDecoder(\"utf8\", { fatal: true });\n\nfunction utf8SequenceLength(byte: number): number {\n\tif (byte >= 0xc2 && byte <= 0xdf) return 2;\n\tif (byte >= 0xe0 && byte <= 0xef) return 3;\n\tif (byte >= 0xf0 && byte <= 0xf4) return 4;\n\treturn 0;\n}\n\nfunction isContinuation(byte: number): boolean {\n\treturn byte >= 0x80 && byte <= 0xbf;\n}\n\nfunction isValidUtf8Sequence(bytes: Buffer, index: number, length: number): boolean {\n\tconst first = bytes[index] ?? 0;\n\tconst second = bytes[index + 1] ?? 0;\n\tif (!isContinuation(second)) return false;\n\tif (length === 2) return true;\n\tconst third = bytes[index + 2] ?? 0;\n\tif (!isContinuation(third)) return false;\n\tif (first === 0xe0 && second < 0xa0) return false;\n\tif (first === 0xed && second > 0x9f) return false;\n\tif (length === 3) return true;\n\tconst fourth = bytes[index + 3] ?? 0;\n\tif (!isContinuation(fourth)) return false;\n\tif (first === 0xf0 && second < 0x90) return false;\n\tif (first === 0xf4 && second > 0x8f) return false;\n\treturn true;\n}\n\nfunction decodeWindows1252Byte(byte: number): string {\n\tif (byte >= 0x80 && byte <= 0x9f) return WINDOWS_1252_EXTENSION[byte - 0x80] ?? \"\\ufffd\";\n\treturn String.fromCodePoint(byte);\n}\n\n/**\n * Decode valid UTF-8 sequences while recovering isolated legacy Windows-1252 bytes. ASCII is\n * shared by both encodings, and at most three trailing bytes are retained across stream chunks.\n */\nclass WindowsCompatibleShellOutputDecoder implements ShellOutputDecoder {\n\tprivate pending = Buffer.alloc(0);\n\n\tdecode(input: Uint8Array = Buffer.alloc(0), options: { stream?: boolean } = {}): string {\n\t\tconst incoming = Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n\t\tconst bytes = this.pending.length > 0 ? Buffer.concat([this.pending, incoming]) : incoming;\n\t\tthis.pending = Buffer.alloc(0);\n\t\tif (bytes.length === 0) return \"\";\n\t\ttry {\n\t\t\treturn FATAL_UTF8_DECODER.decode(bytes);\n\t\t} catch {\n\t\t\t// Legacy bytes or a split trailing UTF-8 sequence need the compatibility scan below.\n\t\t}\n\n\t\tconst decoded: string[] = [];\n\t\tlet utf8Start = 0;\n\t\tlet index = 0;\n\t\tconst appendUtf8 = (end: number): void => {\n\t\t\tif (end > utf8Start) decoded.push(bytes.subarray(utf8Start, end).toString(\"utf8\"));\n\t\t};\n\n\t\twhile (index < bytes.length) {\n\t\t\tconst byte = bytes[index] ?? 0;\n\t\t\tif (byte <= 0x7f) {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst sequenceLength = utf8SequenceLength(byte);\n\t\t\tif (sequenceLength > 0 && index + sequenceLength > bytes.length && options.stream === true) {\n\t\t\t\tappendUtf8(index);\n\t\t\t\tthis.pending = Buffer.from(bytes.subarray(index));\n\t\t\t\treturn decoded.join(\"\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tsequenceLength > 0 &&\n\t\t\t\tindex + sequenceLength <= bytes.length &&\n\t\t\t\tisValidUtf8Sequence(bytes, index, sequenceLength)\n\t\t\t) {\n\t\t\t\tindex += sequenceLength;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tappendUtf8(index);\n\t\t\tdecoded.push(decodeWindows1252Byte(byte));\n\t\t\tindex += 1;\n\t\t\tutf8Start = index;\n\t\t}\n\n\t\tappendUtf8(bytes.length);\n\t\treturn decoded.join(\"\");\n\t}\n}\n\nexport function createShellOutputDecoder(windowsCompatible = false): ShellOutputDecoder {\n\treturn windowsCompatible ? new WindowsCompatibleShellOutputDecoder() : new TextDecoder();\n}\n"]}
@@ -22,17 +22,20 @@
22
22
  * process; the direct child's own exit is what unblocks the sentinel line, exactly like the
23
23
  * per-command backend and like bash's stdio inheritance above. The bounded consequence: a native
24
24
  * command's stderr no longer merges into the session's stdout pipe (there is no capturing pipeline
25
- * stage to merge it) — it arrives on the session's own stderr pipe instead, forwarded via
26
- * `onStderr` -> `onData` same as the shell's own diagnostics. PowerShell 5.1's habit of wrapping
27
- * redirected stderr text in a `NativeCommandError` record also disappears, which is an accuracy
28
- * improvement (the raw stderr bytes are reported, not a wrapped/duplicated rendering of them).
25
+ * stage to merge it) — it arrives on the session's own stderr pipe instead. A nonce-bearing barrier
26
+ * on that pipe joins it deterministically with the stdout completion frame before the command
27
+ * resolves. PowerShell 5.1's habit of wrapping redirected stderr text in a `NativeCommandError`
28
+ * record also disappears, which is an accuracy improvement (the raw stderr bytes are reported,
29
+ * not a wrapped/duplicated rendering of them).
29
30
  *
30
31
  * Kill semantics: timeout/abort/silence kill the WHOLE session process tree (a hung foreground
31
32
  * command cannot be killed individually without job control) and the next exec respawns a fresh
32
33
  * session, losing accumulated shell state by design. A command that exits the shell itself
33
34
  * (`exit 3`) reports the shell's exit code and also respawns lazily afterwards.
34
35
  */
35
- import { type PlatformShellToolName } from "../../utils/shell.ts";
36
+ import { type ChildProcess, type SpawnOptions } from "child_process";
37
+ import { type PlatformShellToolName, type ShellConfig } from "../../utils/shell.ts";
38
+ export { POWERSHELL_SESSION_READY_MARKER, POWERSHELL_SESSION_STDERR_READY_MARKER, } from "../../utils/powershell-session-protocol.ts";
36
39
  export interface ShellSessionExecOptions {
37
40
  onData: (data: Buffer) => void;
38
41
  signal?: AbortSignal;
@@ -42,6 +45,11 @@ export interface ShellSessionExecOptions {
42
45
  silenceMs?: number;
43
46
  env?: NodeJS.ProcessEnv;
44
47
  }
48
+ export interface PersistentShellSessionOptions {
49
+ resolvePowerShellCandidates?: () => ShellConfig[];
50
+ spawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;
51
+ startupTimeoutMs?: number;
52
+ }
45
53
  /**
46
54
  * The whole command is heredoc-quoted data: eval keeps syntax errors contained (a raw syntax
47
55
  * error on the session's stdin would abort the shell), and the random delimiter makes content
@@ -54,20 +62,29 @@ export declare function buildPowerShellWire(command: string, nonce: string, cdTo
54
62
  export declare class PersistentShellSession {
55
63
  private readonly key;
56
64
  private readonly kind;
65
+ private readonly resolvePowerShellCandidates;
66
+ private readonly spawnProcess;
67
+ private readonly startupTimeoutMs;
57
68
  private readonly coordinator;
58
69
  private childEnv;
59
70
  private lastRequestedCwd;
60
71
  private activeExec;
72
+ private rejectStartup;
61
73
  private disposed;
62
- constructor(key: string, kind: PlatformShellToolName);
74
+ constructor(key: string, kind: PlatformShellToolName, options?: PersistentShellSessionOptions);
63
75
  get sessionKind(): PlatformShellToolName;
64
76
  /** Serialized: one command at a time per session, later calls queue behind earlier ones. */
65
77
  exec(command: string, cwd: string, options: ShellSessionExecOptions): Promise<{
66
78
  exitCode: number | null;
67
79
  }>;
80
+ /** Start and validate the long-lived shell before the first user command. Idempotent per session. */
81
+ prewarm(cwd: string, env?: NodeJS.ProcessEnv): Promise<void>;
68
82
  dispose(): void;
69
83
  private execNow;
70
84
  private spawnChild;
85
+ private spawnPowerShellChild;
86
+ private spawnPowerShellCandidate;
87
+ private attachReadyChild;
71
88
  private resetChildState;
72
89
  private killChild;
73
90
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shell-session.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAMH,OAAO,EAA+B,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAO/F,MAAM,WAAW,uBAAuB;IACvC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kGAAkG;IAClG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAUD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,KA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