tftsr-devops_investigation/node_modules/degenerator/dist/compile.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

107 lines
4.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compile = void 0;
const util_1 = require("util");
const degenerator_1 = require("./degenerator");
function compile(qjs, code, returnName, options = {}) {
const compiled = (0, degenerator_1.degenerator)(code, options.names ?? []);
const vm = qjs.newContext();
// Add functions to global
if (options.sandbox) {
for (const [name, value] of Object.entries(options.sandbox)) {
if (typeof value !== 'function') {
throw new Error(`Expected a "function" for sandbox property \`${name}\`, but got "${typeof value}"`);
}
const fnHandle = vm.newFunction(name, (...args) => {
const result = value(...args.map((arg) => quickJSHandleToHost(vm, arg)));
vm.runtime.executePendingJobs();
return hostToQuickJSHandle(vm, result);
});
fnHandle.consume((handle) => vm.setProp(vm.global, name, handle));
}
}
const fnResult = vm.evalCode(`${compiled};${returnName}`, options.filename);
const fn = vm.unwrapResult(fnResult);
const t = vm.typeof(fn);
if (t !== 'function') {
throw new Error(`Expected a "function" named \`${returnName}\` to be defined, but got "${t}"`);
}
const r = async function (...args) {
let promiseHandle;
let resolvedHandle;
try {
const result = vm.callFunction(fn, vm.undefined, ...args.map((arg) => hostToQuickJSHandle(vm, arg)));
promiseHandle = vm.unwrapResult(result);
const resolvedResultP = vm.resolvePromise(promiseHandle);
vm.runtime.executePendingJobs();
const resolvedResult = await resolvedResultP;
resolvedHandle = vm.unwrapResult(resolvedResult);
return quickJSHandleToHost(vm, resolvedHandle);
}
catch (err) {
if (err && typeof err === 'object' && 'cause' in err && err.cause) {
if (typeof err.cause === 'object' &&
'stack' in err.cause &&
'name' in err.cause &&
'message' in err.cause &&
typeof err.cause.stack === 'string' &&
typeof err.cause.name === 'string' &&
typeof err.cause.message === 'string') {
// QuickJS Error `stack` does not include the name +
// message, so patch those in to behave more like V8
err.cause.stack = `${err.cause.name}: ${err.cause.message}\n${err.cause.stack}`;
}
throw err.cause;
}
throw err;
}
finally {
promiseHandle?.dispose();
resolvedHandle?.dispose();
}
};
Object.defineProperty(r, 'toString', {
value: () => compiled,
enumerable: false,
});
return r;
}
exports.compile = compile;
function quickJSHandleToHost(vm, val) {
return vm.dump(val);
}
function hostToQuickJSHandle(vm, val) {
if (typeof val === 'undefined') {
return vm.undefined;
}
else if (val === null) {
return vm.null;
}
else if (typeof val === 'string') {
return vm.newString(val);
}
else if (typeof val === 'number') {
return vm.newNumber(val);
}
else if (typeof val === 'bigint') {
return vm.newBigInt(val);
}
else if (typeof val === 'boolean') {
return val ? vm.true : vm.false;
}
else if (util_1.types.isPromise(val)) {
const promise = vm.newPromise();
promise.settled.then(vm.runtime.executePendingJobs);
val.then((r) => {
promise.resolve(hostToQuickJSHandle(vm, r));
}, (err) => {
promise.reject(hostToQuickJSHandle(vm, err));
});
return promise.handle;
}
else if (util_1.types.isNativeError(val)) {
return vm.newError(val);
}
throw new Error(`Unsupported value: ${val}`);
}
//# sourceMappingURL=compile.js.map