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
3.7 KiB
JavaScript
142 lines
3.7 KiB
JavaScript
/*
|
|
Copyright (c) 2014-2021, Matteo Collina <hello@matteocollina.com>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const { Transform } = require('stream')
|
|
const { StringDecoder } = require('string_decoder')
|
|
const kLast = Symbol('last')
|
|
const kDecoder = Symbol('decoder')
|
|
|
|
function transform (chunk, enc, cb) {
|
|
let list
|
|
if (this.overflow) { // Line buffer is full. Skip to start of next line.
|
|
const buf = this[kDecoder].write(chunk)
|
|
list = buf.split(this.matcher)
|
|
|
|
if (list.length === 1) return cb() // Line ending not found. Discard entire chunk.
|
|
|
|
// Line ending found. Discard trailing fragment of previous line and reset overflow state.
|
|
list.shift()
|
|
this.overflow = false
|
|
} else {
|
|
this[kLast] += this[kDecoder].write(chunk)
|
|
list = this[kLast].split(this.matcher)
|
|
}
|
|
|
|
this[kLast] = list.pop()
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
try {
|
|
push(this, this.mapper(list[i]))
|
|
} catch (error) {
|
|
return cb(error)
|
|
}
|
|
}
|
|
|
|
this.overflow = this[kLast].length > this.maxLength
|
|
if (this.overflow && !this.skipOverflow) {
|
|
cb(new Error('maximum buffer reached'))
|
|
return
|
|
}
|
|
|
|
cb()
|
|
}
|
|
|
|
function flush (cb) {
|
|
// forward any gibberish left in there
|
|
this[kLast] += this[kDecoder].end()
|
|
|
|
if (this[kLast]) {
|
|
try {
|
|
push(this, this.mapper(this[kLast]))
|
|
} catch (error) {
|
|
return cb(error)
|
|
}
|
|
}
|
|
|
|
cb()
|
|
}
|
|
|
|
function push (self, val) {
|
|
if (val !== undefined) {
|
|
self.push(val)
|
|
}
|
|
}
|
|
|
|
function noop (incoming) {
|
|
return incoming
|
|
}
|
|
|
|
function split (matcher, mapper, options) {
|
|
// Set defaults for any arguments not supplied.
|
|
matcher = matcher || /\r?\n/
|
|
mapper = mapper || noop
|
|
options = options || {}
|
|
|
|
// Test arguments explicitly.
|
|
switch (arguments.length) {
|
|
case 1:
|
|
// If mapper is only argument.
|
|
if (typeof matcher === 'function') {
|
|
mapper = matcher
|
|
matcher = /\r?\n/
|
|
// If options is only argument.
|
|
} else if (typeof matcher === 'object' && !(matcher instanceof RegExp) && !matcher[Symbol.split]) {
|
|
options = matcher
|
|
matcher = /\r?\n/
|
|
}
|
|
break
|
|
|
|
case 2:
|
|
// If mapper and options are arguments.
|
|
if (typeof matcher === 'function') {
|
|
options = mapper
|
|
mapper = matcher
|
|
matcher = /\r?\n/
|
|
// If matcher and options are arguments.
|
|
} else if (typeof mapper === 'object') {
|
|
options = mapper
|
|
mapper = noop
|
|
}
|
|
}
|
|
|
|
options = Object.assign({}, options)
|
|
options.autoDestroy = true
|
|
options.transform = transform
|
|
options.flush = flush
|
|
options.readableObjectMode = true
|
|
|
|
const stream = new Transform(options)
|
|
|
|
stream[kLast] = ''
|
|
stream[kDecoder] = new StringDecoder('utf8')
|
|
stream.matcher = matcher
|
|
stream.mapper = mapper
|
|
stream.maxLength = options.maxLength
|
|
stream.skipOverflow = options.skipOverflow || false
|
|
stream.overflow = false
|
|
stream._destroy = function (err, cb) {
|
|
// Weird Node v12 bug that we need to work around
|
|
this._writableState.errorEmitted = false
|
|
cb(err)
|
|
}
|
|
|
|
return stream
|
|
}
|
|
|
|
module.exports = split
|