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>
142 lines
5.0 KiB
JavaScript
142 lines
5.0 KiB
JavaScript
import { isTag, hasChildren } from "domhandler";
|
|
/**
|
|
* Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param node Node to search. Will be included in the result set if it matches.
|
|
* @param recurse Also consider child nodes.
|
|
* @param limit Maximum number of nodes to return.
|
|
* @returns All nodes passing `test`.
|
|
*/
|
|
export function filter(test, node, recurse = true, limit = Infinity) {
|
|
return find(test, Array.isArray(node) ? node : [node], recurse, limit);
|
|
}
|
|
/**
|
|
* Search an array of nodes and their children for nodes passing a test function.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param nodes Array of nodes to search.
|
|
* @param recurse Also consider child nodes.
|
|
* @param limit Maximum number of nodes to return.
|
|
* @returns All nodes passing `test`.
|
|
*/
|
|
export function find(test, nodes, recurse, limit) {
|
|
const result = [];
|
|
/** Stack of the arrays we are looking at. */
|
|
const nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
|
|
/** Stack of the indices within the arrays. */
|
|
const indexStack = [0];
|
|
for (;;) {
|
|
// First, check if the current array has any more elements to look at.
|
|
if (indexStack[0] >= nodeStack[0].length) {
|
|
// If we have no more arrays to look at, we are done.
|
|
if (indexStack.length === 1) {
|
|
return result;
|
|
}
|
|
// Otherwise, remove the current array from the stack.
|
|
nodeStack.shift();
|
|
indexStack.shift();
|
|
// Loop back to the start to continue with the next array.
|
|
continue;
|
|
}
|
|
const elem = nodeStack[0][indexStack[0]++];
|
|
if (test(elem)) {
|
|
result.push(elem);
|
|
if (--limit <= 0)
|
|
return result;
|
|
}
|
|
if (recurse && hasChildren(elem) && elem.children.length > 0) {
|
|
/*
|
|
* Add the children to the stack. We are depth-first, so this is
|
|
* the next array we look at.
|
|
*/
|
|
indexStack.unshift(0);
|
|
nodeStack.unshift(elem.children);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param nodes Array of nodes to search.
|
|
* @returns The first node in the array that passes `test`.
|
|
* @deprecated Use `Array.prototype.find` directly.
|
|
*/
|
|
export function findOneChild(test, nodes) {
|
|
return nodes.find(test);
|
|
}
|
|
/**
|
|
* Finds one element in a tree that passes a test.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param nodes Node or array of nodes to search.
|
|
* @param recurse Also consider child nodes.
|
|
* @returns The first node that passes `test`.
|
|
*/
|
|
export function findOne(test, nodes, recurse = true) {
|
|
const searchedNodes = Array.isArray(nodes) ? nodes : [nodes];
|
|
for (let i = 0; i < searchedNodes.length; i++) {
|
|
const node = searchedNodes[i];
|
|
if (isTag(node) && test(node)) {
|
|
return node;
|
|
}
|
|
if (recurse && hasChildren(node) && node.children.length > 0) {
|
|
const found = findOne(test, node.children, true);
|
|
if (found)
|
|
return found;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* Checks if a tree of nodes contains at least one node passing a test.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param nodes Array of nodes to search.
|
|
* @returns Whether a tree of nodes contains at least one node passing the test.
|
|
*/
|
|
export function existsOne(test, nodes) {
|
|
return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => (isTag(node) && test(node)) ||
|
|
(hasChildren(node) && existsOne(test, node.children)));
|
|
}
|
|
/**
|
|
* Search an array of nodes and their children for elements passing a test function.
|
|
*
|
|
* Same as `find`, but limited to elements and with less options, leading to reduced complexity.
|
|
*
|
|
* @category Querying
|
|
* @param test Function to test nodes on.
|
|
* @param nodes Array of nodes to search.
|
|
* @returns All nodes passing `test`.
|
|
*/
|
|
export function findAll(test, nodes) {
|
|
const result = [];
|
|
const nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
|
|
const indexStack = [0];
|
|
for (;;) {
|
|
if (indexStack[0] >= nodeStack[0].length) {
|
|
if (nodeStack.length === 1) {
|
|
return result;
|
|
}
|
|
// Otherwise, remove the current array from the stack.
|
|
nodeStack.shift();
|
|
indexStack.shift();
|
|
// Loop back to the start to continue with the next array.
|
|
continue;
|
|
}
|
|
const elem = nodeStack[0][indexStack[0]++];
|
|
if (isTag(elem) && test(elem))
|
|
result.push(elem);
|
|
if (hasChildren(elem) && elem.children.length > 0) {
|
|
indexStack.unshift(0);
|
|
nodeStack.unshift(elem.children);
|
|
}
|
|
}
|
|
}
|
|
//# sourceMappingURL=querying.js.map
|