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>
147 lines
4.2 KiB
JavaScript
147 lines
4.2 KiB
JavaScript
import {once} from 'node:events';
|
|
import {isStream as isNodeStream} from 'is-stream';
|
|
import {throwOnTimeout} from '../terminate/timeout.js';
|
|
import {throwOnCancel} from '../terminate/cancel.js';
|
|
import {throwOnGracefulCancel} from '../terminate/graceful.js';
|
|
import {isStandardStream} from '../utils/standard-stream.js';
|
|
import {TRANSFORM_TYPES} from '../stdio/type.js';
|
|
import {getBufferedData} from '../io/contents.js';
|
|
import {waitForIpcOutput, getBufferedIpcOutput} from '../ipc/buffer-messages.js';
|
|
import {sendIpcInput} from '../ipc/ipc-input.js';
|
|
import {waitForAllStream} from './all-async.js';
|
|
import {waitForStdioStreams} from './stdio.js';
|
|
import {waitForExit, waitForSuccessfulExit} from './exit-async.js';
|
|
import {waitForStream} from './wait-stream.js';
|
|
|
|
// Retrieve result of subprocess: exit code, signal, error, streams (stdout/stderr/all)
|
|
export const waitForSubprocessResult = async ({
|
|
subprocess,
|
|
options: {
|
|
encoding,
|
|
buffer,
|
|
maxBuffer,
|
|
lines,
|
|
timeoutDuration: timeout,
|
|
cancelSignal,
|
|
gracefulCancel,
|
|
forceKillAfterDelay,
|
|
stripFinalNewline,
|
|
ipc,
|
|
ipcInput,
|
|
},
|
|
context,
|
|
verboseInfo,
|
|
fileDescriptors,
|
|
originalStreams,
|
|
onInternalError,
|
|
controller,
|
|
}) => {
|
|
const exitPromise = waitForExit(subprocess, context);
|
|
const streamInfo = {
|
|
originalStreams,
|
|
fileDescriptors,
|
|
subprocess,
|
|
exitPromise,
|
|
propagating: false,
|
|
};
|
|
|
|
const stdioPromises = waitForStdioStreams({
|
|
subprocess,
|
|
encoding,
|
|
buffer,
|
|
maxBuffer,
|
|
lines,
|
|
stripFinalNewline,
|
|
verboseInfo,
|
|
streamInfo,
|
|
});
|
|
const allPromise = waitForAllStream({
|
|
subprocess,
|
|
encoding,
|
|
buffer,
|
|
maxBuffer,
|
|
lines,
|
|
stripFinalNewline,
|
|
verboseInfo,
|
|
streamInfo,
|
|
});
|
|
const ipcOutput = [];
|
|
const ipcOutputPromise = waitForIpcOutput({
|
|
subprocess,
|
|
buffer,
|
|
maxBuffer,
|
|
ipc,
|
|
ipcOutput,
|
|
verboseInfo,
|
|
});
|
|
const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);
|
|
const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);
|
|
|
|
try {
|
|
return await Promise.race([
|
|
Promise.all([
|
|
{},
|
|
waitForSuccessfulExit(exitPromise),
|
|
Promise.all(stdioPromises),
|
|
allPromise,
|
|
ipcOutputPromise,
|
|
sendIpcInput(subprocess, ipcInput),
|
|
...originalPromises,
|
|
...customStreamsEndPromises,
|
|
]),
|
|
onInternalError,
|
|
throwOnSubprocessError(subprocess, controller),
|
|
...throwOnTimeout(subprocess, timeout, context, controller),
|
|
...throwOnCancel({
|
|
subprocess,
|
|
cancelSignal,
|
|
gracefulCancel,
|
|
context,
|
|
controller,
|
|
}),
|
|
...throwOnGracefulCancel({
|
|
subprocess,
|
|
cancelSignal,
|
|
gracefulCancel,
|
|
forceKillAfterDelay,
|
|
context,
|
|
controller,
|
|
}),
|
|
]);
|
|
} catch (error) {
|
|
context.terminationReason ??= 'other';
|
|
return Promise.all([
|
|
{error},
|
|
exitPromise,
|
|
Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise))),
|
|
getBufferedData(allPromise),
|
|
getBufferedIpcOutput(ipcOutputPromise, ipcOutput),
|
|
Promise.allSettled(originalPromises),
|
|
Promise.allSettled(customStreamsEndPromises),
|
|
]);
|
|
}
|
|
};
|
|
|
|
// Transforms replace `subprocess.std*`, which means they are not exposed to users.
|
|
// However, we still want to wait for their completion.
|
|
const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>
|
|
originalStreams.map((stream, fdNumber) => stream === subprocess.stdio[fdNumber]
|
|
? undefined
|
|
: waitForStream(stream, fdNumber, streamInfo));
|
|
|
|
// Some `stdin`/`stdout`/`stderr` options create a stream, e.g. when passing a file path.
|
|
// The `.pipe()` method automatically ends that stream when `subprocess` ends.
|
|
// This makes sure we wait for the completion of those streams, in order to catch any error.
|
|
const waitForCustomStreamsEnd = (fileDescriptors, streamInfo) => fileDescriptors.flatMap(({stdioItems}, fdNumber) => stdioItems
|
|
.filter(({value, stream = value}) => isNodeStream(stream, {checkOpen: false}) && !isStandardStream(stream))
|
|
.map(({type, value, stream = value}) => waitForStream(stream, fdNumber, streamInfo, {
|
|
isSameDirection: TRANSFORM_TYPES.has(type),
|
|
stopOnExit: type === 'native',
|
|
})));
|
|
|
|
// Fails when the subprocess emits an `error` event
|
|
const throwOnSubprocessError = async (subprocess, {signal}) => {
|
|
const [error] = await once(subprocess, 'error', {signal});
|
|
throw error;
|
|
};
|