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>
164 lines
4.6 KiB
JavaScript
164 lines
4.6 KiB
JavaScript
import {spawnSync} from 'node:child_process';
|
|
import {handleCommand} from '../arguments/command.js';
|
|
import {normalizeOptions} from '../arguments/options.js';
|
|
import {concatenateShell} from '../arguments/shell.js';
|
|
import {makeError, makeEarlyError, makeSuccessResult} from '../return/result.js';
|
|
import {handleResult} from '../return/reject.js';
|
|
import {handleStdioSync} from '../stdio/handle-sync.js';
|
|
import {stripNewline} from '../io/strip-newline.js';
|
|
import {addInputOptionsSync} from '../io/input-sync.js';
|
|
import {transformOutputSync} from '../io/output-sync.js';
|
|
import {getMaxBufferSync} from '../io/max-buffer.js';
|
|
import {getAllSync} from '../resolve/all-sync.js';
|
|
import {getExitResultSync} from '../resolve/exit-sync.js';
|
|
|
|
// Main shared logic for all sync methods: `execaSync()`, `$.sync()`
|
|
export const execaCoreSync = (rawFile, rawArguments, rawOptions) => {
|
|
const {file, commandArguments, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArguments, rawOptions);
|
|
const result = spawnSubprocessSync({
|
|
file,
|
|
commandArguments,
|
|
options,
|
|
command,
|
|
escapedCommand,
|
|
verboseInfo,
|
|
fileDescriptors,
|
|
startTime,
|
|
});
|
|
return handleResult(result, verboseInfo, options);
|
|
};
|
|
|
|
// Compute arguments to pass to `child_process.spawnSync()`
|
|
const handleSyncArguments = (rawFile, rawArguments, rawOptions) => {
|
|
const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArguments, rawOptions);
|
|
const syncOptions = normalizeSyncOptions(rawOptions);
|
|
const {file, commandArguments, options} = normalizeOptions(rawFile, rawArguments, syncOptions);
|
|
validateSyncOptions(options);
|
|
const fileDescriptors = handleStdioSync(options, verboseInfo);
|
|
return {
|
|
file,
|
|
commandArguments,
|
|
command,
|
|
escapedCommand,
|
|
startTime,
|
|
verboseInfo,
|
|
options,
|
|
fileDescriptors,
|
|
};
|
|
};
|
|
|
|
// Options normalization logic specific to sync methods
|
|
const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;
|
|
|
|
// Options validation logic specific to sync methods
|
|
const validateSyncOptions = ({ipc, ipcInput, detached, cancelSignal}) => {
|
|
if (ipcInput) {
|
|
throwInvalidSyncOption('ipcInput');
|
|
}
|
|
|
|
if (ipc) {
|
|
throwInvalidSyncOption('ipc: true');
|
|
}
|
|
|
|
if (detached) {
|
|
throwInvalidSyncOption('detached: true');
|
|
}
|
|
|
|
if (cancelSignal) {
|
|
throwInvalidSyncOption('cancelSignal');
|
|
}
|
|
};
|
|
|
|
const throwInvalidSyncOption = value => {
|
|
throw new TypeError(`The "${value}" option cannot be used with synchronous methods.`);
|
|
};
|
|
|
|
const spawnSubprocessSync = ({file, commandArguments, options, command, escapedCommand, verboseInfo, fileDescriptors, startTime}) => {
|
|
const syncResult = runSubprocessSync({
|
|
file,
|
|
commandArguments,
|
|
options,
|
|
command,
|
|
escapedCommand,
|
|
fileDescriptors,
|
|
startTime,
|
|
});
|
|
if (syncResult.failed) {
|
|
return syncResult;
|
|
}
|
|
|
|
const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getExitResultSync(syncResult, options);
|
|
const {output, error = resultError} = transformOutputSync({
|
|
fileDescriptors,
|
|
syncResult,
|
|
options,
|
|
isMaxBuffer,
|
|
verboseInfo,
|
|
});
|
|
const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, fdNumber));
|
|
const all = stripNewline(getAllSync(output, options), options, 'all');
|
|
return getSyncResult({
|
|
error,
|
|
exitCode,
|
|
signal,
|
|
timedOut,
|
|
isMaxBuffer,
|
|
stdio,
|
|
all,
|
|
options,
|
|
command,
|
|
escapedCommand,
|
|
startTime,
|
|
});
|
|
};
|
|
|
|
const runSubprocessSync = ({file, commandArguments, options, command, escapedCommand, fileDescriptors, startTime}) => {
|
|
try {
|
|
addInputOptionsSync(fileDescriptors, options);
|
|
const normalizedOptions = normalizeSpawnSyncOptions(options);
|
|
return spawnSync(...concatenateShell(file, commandArguments, normalizedOptions));
|
|
} catch (error) {
|
|
return makeEarlyError({
|
|
error,
|
|
command,
|
|
escapedCommand,
|
|
fileDescriptors,
|
|
options,
|
|
startTime,
|
|
isSync: true,
|
|
});
|
|
}
|
|
};
|
|
|
|
// The `encoding` option is handled by Execa, not by `child_process.spawnSync()`
|
|
const normalizeSpawnSyncOptions = ({encoding, maxBuffer, ...options}) => ({...options, encoding: 'buffer', maxBuffer: getMaxBufferSync(maxBuffer)});
|
|
|
|
const getSyncResult = ({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime}) => error === undefined
|
|
? makeSuccessResult({
|
|
command,
|
|
escapedCommand,
|
|
stdio,
|
|
all,
|
|
ipcOutput: [],
|
|
options,
|
|
startTime,
|
|
})
|
|
: makeError({
|
|
error,
|
|
command,
|
|
escapedCommand,
|
|
timedOut,
|
|
isCanceled: false,
|
|
isGracefullyCanceled: false,
|
|
isMaxBuffer,
|
|
isForcefullyTerminated: false,
|
|
exitCode,
|
|
signal,
|
|
stdio,
|
|
all,
|
|
ipcOutput: [],
|
|
options,
|
|
startTime,
|
|
isSync: true,
|
|
});
|