tftsr-devops_investigation/node_modules/execa/lib/io/max-buffer.js
Shaun Arman 8839075805 feat: initial implementation of TFTSR IT Triage & RCA application
Implements Phases 1-8 of the TFTSR implementation plan.

Rust backend (Tauri 2.x, src-tauri/):
- Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama
- PII detection engine: 11 regex patterns with overlap resolution
- SQLCipher AES-256 encrypted database with 10 versioned migrations
- 28 Tauri IPC commands for triage, analysis, document, and system ops
- Ollama: hardware probe, model recommendations, pull/delete with events
- RCA and blameless post-mortem Markdown document generators
- PDF export via printpdf
- Audit log: SHA-256 hash of every external data send
- Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2)

Frontend (React 18 + TypeScript + Vite, src/):
- 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings
- 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives
- 3 Zustand stores: session, settings (persisted), history
- Type-safe tauriCommands.ts matching Rust backend types exactly
- 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs)

DevOps:
- .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push
- .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload

Verified:
- cargo check: zero errors
- tsc --noEmit: zero errors
- vitest run: 13/13 unit tests passing

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:36:25 -05:00

90 lines
2.8 KiB
JavaScript

import {MaxBufferError} from 'get-stream';
import {getStreamName} from '../utils/standard-stream.js';
import {getFdSpecificValue} from '../arguments/specific.js';
// When the `maxBuffer` option is hit, a MaxBufferError is thrown.
// The stream is aborted, then specific information is kept for the error message.
export const handleMaxBuffer = ({error, stream, readableObjectMode, lines, encoding, fdNumber}) => {
if (!(error instanceof MaxBufferError)) {
throw error;
}
if (fdNumber === 'all') {
return error;
}
const unit = getMaxBufferUnit(readableObjectMode, lines, encoding);
error.maxBufferInfo = {fdNumber, unit};
stream.destroy();
throw error;
};
const getMaxBufferUnit = (readableObjectMode, lines, encoding) => {
if (readableObjectMode) {
return 'objects';
}
if (lines) {
return 'lines';
}
if (encoding === 'buffer') {
return 'bytes';
}
return 'characters';
};
// Check the `maxBuffer` option with `result.ipcOutput`
export const checkIpcMaxBuffer = (subprocess, ipcOutput, maxBuffer) => {
if (ipcOutput.length !== maxBuffer) {
return;
}
const error = new MaxBufferError();
error.maxBufferInfo = {fdNumber: 'ipc'};
throw error;
};
// Error message when `maxBuffer` is hit
export const getMaxBufferMessage = (error, maxBuffer) => {
const {streamName, threshold, unit} = getMaxBufferInfo(error, maxBuffer);
return `Command's ${streamName} was larger than ${threshold} ${unit}`;
};
const getMaxBufferInfo = (error, maxBuffer) => {
if (error?.maxBufferInfo === undefined) {
return {streamName: 'output', threshold: maxBuffer[1], unit: 'bytes'};
}
const {maxBufferInfo: {fdNumber, unit}} = error;
delete error.maxBufferInfo;
const threshold = getFdSpecificValue(maxBuffer, fdNumber);
if (fdNumber === 'ipc') {
return {streamName: 'IPC output', threshold, unit: 'messages'};
}
return {streamName: getStreamName(fdNumber), threshold, unit};
};
// The only way to apply `maxBuffer` with `spawnSync()` is to use the native `maxBuffer` option Node.js provides.
// However, this has multiple limitations, and cannot behave the exact same way as the async behavior.
// When the `maxBuffer` is hit, a `ENOBUFS` error is thrown.
export const isMaxBufferSync = (resultError, output, maxBuffer) => resultError?.code === 'ENOBUFS'
&& output !== null
&& output.some(result => result !== null && result.length > getMaxBufferSync(maxBuffer));
// When `maxBuffer` is hit, ensure the result is truncated
export const truncateMaxBufferSync = (result, isMaxBuffer, maxBuffer) => {
if (!isMaxBuffer) {
return result;
}
const maxBufferValue = getMaxBufferSync(maxBuffer);
return result.length > maxBufferValue ? result.slice(0, maxBufferValue) : result;
};
// `spawnSync()` does not allow differentiating `maxBuffer` per file descriptor, so we always use `stdout`
export const getMaxBufferSync = ([, stdoutMaxBuffer]) => stdoutMaxBuffer;